I have a template sensor that includes an if block to return the desired volume from an input_number based on the time of day:
sonos_family_room_volume:
friendly_name: Sonos Family Room Volume
value_template: >
{% if is_state('binary_sensor.early_morning','on') %}
{{states('input_number.set_family_room_volume_wakeup')|int }}
{% elif is_state('binary_sensor.daytime','on') %}
{{states('input_number.set_family_room_volume_daytime')|int }}
{% elif is_state('binary_sensor.sleeping','on') %}
{{states('input_number.set_family_room_volume_bedtime')|int }}
{% elif
is_state('binary_sensor.early_morning','off') and
is_state('binary_sensor.daytime','off') and
is_state('binary_sensor.sleeping','off') %}
{{states('input_number.set_family_room_volume_wakeup')|int }}
{% endif %}
I then have a function in AD that gets the state from the sensor (value
is sensor_temp.sonos_family_room_volume
):
if value.split(".")[0] in ['sensor_temp']:
sensor_entity = 'sensor.'+value. Split(".")[1]
temporary = self.get_state(sensor_entity, "state")
When triggered, I get the proper value as expected.
Then, I updated the template with an else
portion:
{% if is_state('input_boolean.guests_in_lower_level_bedroom','off') %}
{% if is_state('binary_sensor.early_morning','on') %}
{{states('input_number.set_family_room_volume_wakeup')|int }}
{% elif is_state('binary_sensor.daytime','on') %}
{{states('input_number.set_family_room_volume_daytime')|int }}
{% elif is_state('binary_sensor.sleeping','on') %}
{{states('input_number.set_family_room_volume_bedtime')|int }}
{% elif
is_state('binary_sensor.early_morning','off') and
is_state('binary_sensor.daytime','off') and
is_state('binary_sensor.sleeping','off') %}
{{states('input_number.set_family_room_volume_wakeup')|int }}
{% endif %}
{% else %} <---------------- New Else Statement
{% if is_state('binary_sensor.early_morning','on') %}
{{states('input_number.set_family_room_volume_wakeup_guests')|int }}
{% elif is_state('binary_sensor.daytime','on') %}
{{states('input_number.set_family_room_volume_daytime_guests')|int }}
{% elif is_state('binary_sensor.sleeping','on') %}
{{states('input_number.set_family_room_volume_bedtime_guests')|int }}
{% elif
is_state('binary_sensor.early_morning','off') and
is_state('binary_sensor.daytime','off') and
is_state('binary_sensor.sleeping','off') %}
{{states('input_number.set_family_room_volume_wakeup_guests')|int }}
{% endif %}
{% endif %}
This update added an else
statement for an input_boolean.guests_in...
is on
. It shows properly in the HA front end and responds appropriately when the input_boolean
is toggled on
and off
. But the get_state
in AD now returns None
, which is not correct.
Is there something where it takes AD a while to update its internal dBase after a template entity is reloaded? I don’t recall having this problem before. I tried reloading the app with the get_state
in it, but that didn’t solve the problem.
But if I reload AD, then it works as expected.
So, after a template update, it appears that AD deletes it from the dBase, then reloads the dBase and that takes a while (or something like that). When I add an additional template sensor, it seems to update almost instantly.
Thoughts on what I’m doing wrong (and that could be my understanding of the update process)?