Hello community,
I am facing a problem that I have read about a few times, but have not yet found a solution for:
I have a simple automation system with a motion detector that turns the light on when movement is detected and the light intensity is below 1500 lx, and turns it off again after 15 seconds of inactivity.
The Tuya motion detector saves its precious battery power by only sending values to the HA when it is activated. This means that after switching on the light, it sends a value of >2400 lx and then goes to sleep.
The next time there is movement in the dark of night, the HA automation interprets: 2400 lx is more than 1500 lx. Condition not met. Light stays off. The automation therefore only works every other time.
Now I have installed HACS “Saver” and let the current lx value be saved at the beginning of the automation. Then I switch on the light. That works so far. Unfortunately, I can’t find a way to use the stored value to overwrite the state of the entity at the end of the automation.
I have read a lot that states are not intended to be overwritten and that the function in the developer tools to set a state is only for testing purposes. But when I set the value to 1, for example, using the developer tools, it affects the real entity value. I can see this in the entity, and the automation works afterwards.
And whatever I can set along this way, I have to be able to script somehow. But I can’t find anything suitable. Does anyone have the right code for this?
Entity: sensor.bewegungsmelderwf1_illuminance
state_class: measurement
unit_of_measurement: lx
device_class: illuminance
friendly_name: BewegungsmelderWF1 illuminance