Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
React Homey – A declarative way to home automation
/*
Disclaimer: This is just a drafted api and not real (yet).
*/
import { useState } from "react"
import ReactHomey, {
// Components
Light,
Fan,
Room,
Group,
// Hooks
useDevices,
useSensor,
useTrigger
} from "react-homey"
const Home = () => {
const [moodlight, setMoodlight] = useState(false)
const devices = useDevices()
const thermostatData = useSensor(devices.findById("Thermostat"))
const isHighTemperature = thermostatData.temperature > 25
// Listen for button presses
useTrigger(() => {
setMoodlight(!moodlight)
}, getIdByName("My Button"))
return (
<Room>
<Fan level={isHighTemperature ? 1 : 0}/>
<Light id={getIdByName("Ceiling Lamp")} power={true} brightness={0.8} />
<Group power={moodlight}>
<Light id={devices.findById("Ambient Lamp 1")} />
<Light id={devices.findById("Ambient Lamp 2")} />
<Light id={devices.findById("Ambient Lamp 3")} />
<Group/>
</Room>
)
}
ReactHomey.render(<Home/>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment