xannor / hass_py_set_state

Home Assistant Python Script to force set an entity state
The Unlicense
44 stars 14 forks source link

Manage the status of the motion sensor #5

Open DivanX10 opened 3 years ago

DivanX10 commented 3 years ago

Hi. I have a motion sensor from xiaomi and a gateway xiaomi 2, the firmware is original. My motion sensors are switched to service mode and they record movement every 5 seconds. I did as you wrote on the forum. The status of the motion sensor is reset after any period of time, even after 5 seconds. But if you walk in front of the motion sensor again, the detected status is not displayed, you need to wait 2 minutes and then it will show the detected status and after 5 seconds (I specified this time) it will reset the detected status to not detected. You can somehow get the home assistant to respond accurately to movement? There is a movement status detected after 5 seconds of no movement - status is not found, then create movement and status must be detected.

I have installed Home Assistant 2020.12.1

Read it here https://community.home-assistant.io/t/how-to-manually-set-state-value-of-sensor/43975/2

1) In configuration.yaml added python_script: config

2) Created the python_scripts folder python_scripts01

3) Created a file set_state.py set_state

4) I inserted your code into it 5) The service is available in the developer panel service_yes

6) Created automation

alias: DD in the corridor deactivating the status description: We check the operation of the creak to deactivate the motion sensor trigger:

xannor commented 3 years ago

All set state does is change the attribute values of the specified entity. With non-existent entities, home assistant will create a generic one the will temporarily hold the values, a restart will erase them since the entity never really existed. With entities provided by integrations, the attributes can be changed, but ultimately the integration controls their values and can reset them whenever it decides to. There is no reliable way to use this to override an existing entity.