I tried to find some topic regarding what I am
Asking for, but did not find it. Is it possible to get the value of the ‘Occupancy’ field for Philips hue motion sensor through python scripting?
I followed the documentation for how to get started with python in home assistant and I have managed to do a hello world through logging and even control some lights, but I can’t get any values from the sensor.
Thank you for providing an answer. I know that I can get this value through home assistant. I have 2 motion sensors downstairs. One is located when you are going down to the basement and the other is at downstairs. This is used to turn on the lights.
I want the lights to turn off when both sensors is not Occupied. In theory This should work when I have an automation and in that I define ```if sensor x && sensor y is not occupied``‘ turn off lights. But this does not work.
So I thought with some python code I could easily make this work. The only thing I struggle with is to get the value of occupancy or what the current state is so that I can assign to a variable in python and do some conditional checks on it.
The sensors are really to detect motion and not occupancy. this something I ran into as well but can overcome it in my situation.
I can see that the sensor state is on detected approximatly 13 seconds
I have setup on the first and second floor.
I achieve some switching based on the light state.
After 11 pm
if motion at first floor, and light second floor = on… turn second floor off.
if motion at second floor and first floor = on, turn light first floor off.
I’ve made a short example maybe for your situation.
I any of the motion sensor changes to not detected, it confirms of the lights are on, and both of the motions are not detecting. Then take action.
alias: Test motion
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.overloop_eerste_motion
to: "off"
- platform: state
entity_id:
- binary_sensor.overloop_tweede_motion
to: "off"
condition:
- condition: device
type: is_on
device_id: 33dbb02fb53549bba2b412172fd4a30b
entity_id: a2f8a7a6e3c96cc24d56409d71520154
domain: light
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.overloop_eerste_motion
state: "off"
- condition: state
entity_id: binary_sensor.overloop_tweede_motion
state: "off"
action:
- type: turn_off
device_id: 33dbb02fb53549bba2b412172fd4a30b
entity_id: a2f8a7a6e3c96cc24d56409d71520154
domain: light
mode: single