I would like to create an input_boolean that is a following sensor for a smart light. When the light is in state on, the boolean is true. When light is in state off, the boolean is false. And here is the thing I can’t figure out…if the light has had power turned off (like at a wall switch), i.e. no connectivity, the boolean is false.
If there are multiple solutions based on network technology, I have both ZigBee (and by extension MQTT) and Wi-Fi bulbs.
Too bad there is not a sticky_input_boolean that you could set a default state for.
You should try out a template with the sensor and filter out the unwanted states ( e. g. “unavailable”). I’m not on a proper PC, so I can’t point you to a recipe. I’ll circle back later.
Here is a sample from my sensors.yaml.
#Make the Watering sensor show Today, Tomorrow or Later
watering_indication_sensor:
friendly_name: "Water Indication"
unique_id: "When_to_Irrigate"
value_template: >-
{% if is_state('sensor.watering_days', '0') %}
Today
{% elif is_state('sensor.watering_days', '1') %}
Tomorrow
{% else %}
Two_Days
{% endif %}
you could modify to something like this
#Make the state a Boolean
Boolean_Light_sensor:
friendly_name: "my_light_boolean"
unique_id: "My_Unique_ID_to_Track_Light"
value_template: >-
{% if is_state('sensor.mylight', 'on') %}
true
{% elif is_state('sensor.mylight', 'off') %}
false
{% else %}
false
{% endif %}
I haven’t tested the modified on my system but the I know the watering days from my sensors.yaml works.
Thanks for the help, BTW, I have it working for one group. This approach works fine on my WiFi bulbs, which go to Unavailable less than a minute after being forcibly turned off. Not for my Zigbee/MQTT ones. They never change state when power is removed. I am running Zigbee2MQTT, is there a way to force a LWT or something when communication is lost? I assume that is where I need to look.
The LWT on Zigbee2MQTT is only for the coordinator, not for individual devices. Have you set ‘report : true’ ?