An automatic hallway light the complex way: zigbee + wifi + python + google translate
So we've had a long standing problem here at home. The upstairs landing is lit by a large chandelier, 12 x 100W bulbs. Its on a dimmer, but it can use a ton of power. When i first moved in, i installed a 3-way dimmer so you could control it from the top and bottom of the stairs. Unfortunately, one of the other inhabitants of the house didn't get the memo that the light could be turned off, meaning ~1200W of power is very commonly left on for days when I'm not here to complain. Since, regardless of the question, overly-complex technology is the answer, I decided to have a try at fixing this.
So lets see, what do we need. Motion sensors, light sensors, a light, and some automation. For this I chose the Xiaomi mi Smart Home. Its a zigbee + wifi gateway, with a light. And, with some hackery, it can be introduced to Home Assistant. The kit came with a motion sensor, a door sensor, and a button. I then added some more sensors for future projects.
Getting the device paired and on the network was a bit complex. Its voice-activated, and Chinese. You can see in the video below.
OK, some Google Translate, and a somewhat hard to use all-chinese app installed on a burner android device, and we are paired and on the 'IoT' network. At first we had to put this on the 'evil' network since it needs to reach the Internet to check for new firmware, but then I moved it over.
OK, the home automation part. I installed the gateway in the top-landing upstairs, its a natural spot for it anyway. I extracted the key and configured it as below.
So now the sequence of events... its dark (less than 300 lumens). There's motion. The light turns on 'white' @ 80% brightness (yes it supports RGB colours but who wants their upstairs landing light to be radioactive green?). When there is no longer motion (it times out after about 1min) it turns off.
Under the hood, the sequence is: motion hits PIR sensor. Sensor is battery-powered zigbee, turns on, sends an event over zigbee to gateway. Gateway sends that over wifi to home assistant. Home assistant then asks over wifi to the gw for how bright it is. Home assistant then sends a lights-on message over wifi. So the side affect is you get not only radiation in the visible light band, but also in the 2.4GHz band to light your way 🙂
xiaomi: discovery_retry: 2 interface: IOT INTERFACE IP gateways: - gw_mac: MY MAC key: MY KEY automations: - id: landing_light_motion alias: Landing light when motion hide_entity: true trigger: platform: state entity_id: binary_sensor.motion_sensor_158d0001875b6b from: 'off' to: 'on' condition: condition: numeric_state entity_id: sensor.illumination_286c0785c002 below: 300 action: - service: light.turn_on entity_id: light.gateway_light_286c0785c002 data: rgb_color: [255, 255, 255] brightness: 80 - service: automation.turn_on data: entity_id: automation.motion_off - id: landing_light_no_motion alias: Landing light when no motion hide_entity: true trigger: platform: state entity_id: binary_sensor.motion_sensor_158d0001875b6b from: 'on' to: 'off' action: - service: light.turn_off entity_id: light.gateway_light_286c0785c002