and then binary sensor that is true if sensor is above some threshold and false if it is below:
binary sensor
lambda: |-
if (id(light).state >= id(threshold)) return true;
if (id(light).state < id(threshold)) return false;
it seems to me that the binary sensor does not follows state updates of sensor if it is based on value of master sensor in lambda. How to update the binary sensor currently? You cannot use on_value and then component.update: binary_sensor because it does not work on binary sensors.
OK, but the code is a bit complicated. The is_sun binary sensor does not update as often as bh1750. It actually does not update until bh1750 goes over threshold, but bh1750 does update every 3 minutes because light changes even if it is still over or under threshold…
It seems to me that if lambda in binary sensor evaluates true and it was true before, then it does not proceed further to on_state, because state actually has not changed. But I need the on_state to run as often as bh1750 updates, even if it is true again. I think I would better move it to interval…
what if I manually publish state of this binary sensor in lambda by id(is_sun).publish_state(true) twice in a row, will it trigger on_state twice as well, or only on first publish?
Why not run the on_state code in the bh1750_illuminance sensor instead with the first step to test against the threshold? The binary_sensor is only ever going to change state when the illuminance sensor sends a new value, so it’ll be run just as often.
Your code does appear to ask it for a new value immediately, though: perhaps that should be the last step in your on_state code, once it’s finished dealing with the current value?