Any ideas as to what is wrong here with the below.
Automation is triggered by either one of two entities air quality, but want the “Room” value to send to a script to send a notification but HA isn’t liking something here.
Config is saying it is ok, but reloading the automations get an error to check.
Thanks!
- alias: 'Bedroom VOCs'
mode: single
trigger:
- platform: state
entity_id: sensor.aarlo_air_quality_small_bedroom
- platform: state
entity_id: sensor:aarlo_air_quality_large_bedroom
condition:
- condition: state
entity_id: input_boolean.kids_bedtime
state: true
- condition: state
entity_id: input_boolean.night_mode
state: false
- condition: numeric_state
entity_id: "{{ trigger.entity_id }}"
above: input_number.abnormal_voc
action:
- service: script.environment
data:
Room: >
{% if trigger.to_state.entity_id == aarlo_air_quality_large_bedroom %} Large
{% else %} Small {% endif %}
The entity_id in the second trigger contains a syntax error. It uses a colon after the word sensor instead of a period.
Valid state values for an input_boolean are 'on' and 'off' as opposed to true/false.
As far as I know, you cannot template the entity_id of a Numeric State Condition.
The action’s template is incorrect. I believe you want this: trigger.to_state.object_id == 'aarlo_air_quality_large_bedroom'
instead of this: trigger.to_state.entity_id == aarlo_air_quality_large_bedroom
In fact the template can be reduced to this:
data:
Room: "{{ trigger.to_state.object_id[18:-8] | title }}"
Please consider marking my post with the Solution tag. Only one post in the thread can be marked. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. Effectively, the topic is resolved. This helps users find answers to similar questions.
- alias: 'Bedroom Temps'
mode: single
trigger:
- platform: state
entity_id:
- sensor.aarlo_temperature_large_bedroom
- sensor.aarlo_temperature_small_bedroom
action:
- variables:
temp: '{{ trigger.to_state.state|float }}'
low: "{{ temp < states('input_number.bedroom_temp_min')|float }}"
high: "{{ temp >= states('input_number.bedroom_temp_max')|float }}"
- condition: template
value_template: "{{ is_state('input_boolean.night_mode', 'off') and (low or high) }}"
- service: script.notification
data:
notify_service: notify.user_mobile_devices
title: "Environment Alert"
subject: "Temperature"
importance: low
channel: Environment
message: "It is {{ 'cold' if low else 'hot' }} in {{ trigger.to_state.object_id[18:-8] | title }} Bedroom. Currently it is {{ temp }} °C"
If it fails to call script.notification then we can insert a call to persistent_notification.create (shown below) to report the values of the variables to help determine what may be wrong.
Diagnostic version
- alias: 'Bedroom Temps'
mode: single
trigger:
- platform: state
entity_id:
- sensor.aarlo_temperature_large_bedroom
- sensor.aarlo_temperature_small_bedroom
action:
- variables:
temp: '{{ trigger.to_state.state|float }}'
low: "{{ temp < states('input_number.bedroom_temp_min')|float }}"
high: "{{ temp >= states('input_number.bedroom_temp_max')|float }}"
- service: persistent_notification.create
data:
title: "{{ now().timestamp() | timestamp_local }}"
message: "{{temp}} °C, Low = {{'yes' if low else 'no'}}, High = {{'yes' if high else 'no'}}"
- condition: template
value_template: "{{ is_state('input_boolean.night_mode', 'off') and (low or high) }}"
- service: script.notification
data:
notify_service: notify.user_mobile_devices
title: "Environment Alert"
subject: "Temperature"
importance: low
channel: Environment
message: "It is {{ 'cold' if low else 'hot' }} in {{ trigger.to_state.object_id[18:-8] | title }} Bedroom. Currently it is {{ temp }} °C"
@123 looks like my version worked. Did a full restart for something else and it just started working, though I had done a restart previously.
Perhaps the input_number didnt take properly.
Thanks for your time though, very much appreciated.