Last active
August 17, 2022 12:03
-
-
Save timolins/0efccf254517773e7763398736dd7661 to your computer and use it in GitHub Desktop.
React Homey – A declarative way to home automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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