Hello,
I am trying the generate an automation, which should send a notification to my iphone, when a sensor != ‘success’. Furthermore I want to have a button which should trigger a switch in HA. I have 7 different thermostats and therefore I want to make the notification and button dynamically (should only get shown when sensor != 'success).
Attached you find my automation, where I have some issues. I believe my syntax of the for and if in the data of ‘Send Notification’, “Wait for Button Response” and “Perform the Selected Action” is wrong. Nevertheless, if i copy it in the development tools it seems to be ok?
alias: Thermostat Notification with Conditional Actions
description: Notify and handle thermostat valve adaptation dynamically.
trigger:
- platform: state
entity_id:
- sensor.thermostat_badezimmer_valve_adapt_status
- sensor.thermostat_buro_valve_adapt_status
- sensor.thermostat_schlafzimmer_valve_adapt_status
- sensor.thermostat_gastezimmer_valve_adapt_status
- sensor.thermostat_vorzimmer_valve_adapt_status
- sensor.thermostat_wohnzimmerfenster_valve_adapt_status
- sensor.thermostat_wohnzimmertur_valve_adapt_status
condition:
- condition: template
value_template: >
{% set thermostats = {
'bathroom': {'sensor': 'sensor.thermostat_badezimmer_valve_adapt_status', 'action_id': 'ADOPT_BATHROOM', 'switch': 'switch.thermostat_badezimmer_valve_adapt_process'},
'buro': {'sensor': 'sensor.thermostat_buro_valve_adapt_status', 'action_id': 'ADOPT_BURO', 'switch': 'switch.thermostat_buro_valve_adapt_process'},
'schlafzimmer': {'sensor': 'sensor.thermostat_schlafzimmer_valve_adapt_status', 'action_id': 'ADOPT_SCHLAFZIMMER', 'switch': 'switch.thermostat_schlafzimmer_valve_adapt_process'},
'gastezimmer': {'sensor': 'sensor.thermostat_gastezimmer_valve_adapt_status', 'action_id': 'ADOPT_GASTEZIMMER', 'switch': 'switch.thermostat_gastezimmer_valve_adapt_process'},
'vorzimmer': {'sensor': 'sensor.thermostat_vorzimmer_valve_adapt_status', 'action_id': 'ADOPT_VORZIMMER', 'switch': 'switch.thermostat_vorzimmer_valve_adapt_process'},
'wohnzimmerfenster': {'sensor': 'sensor.thermostat_wohnzimmerfenster_valve_adapt_status', 'action_id': 'ADOPT_WOHNZIMMERFENSTER', 'switch': 'switch.thermostat_wohnzimmerfenster_valve_adapt_process'},
'wohnzimmertur': {'sensor': 'sensor.thermostat_wohnzimmertur_valve_adapt_status', 'action_id': 'ADOPT_WOHNZIMMERTUR', 'switch': 'switch.thermostat_wohnzimmertur_valve_adapt_process'}
} %}
{{ thermostats | selectattr('sensor', 'defined') | selectattr('sensor', '!=', 'success') | list | length > 0 }}
action:
- alias: "Set up dynamic variables for actions"
variables:
thermostats:
bathroom:
sensor: 'sensor.thermostat_badezimmer_valve_adapt_status'
action_id: 'ADOPT_BATHROOM'
switch: 'switch.thermostat_badezimmer_valve_adapt_process'
buro:
sensor: 'sensor.thermostat_buro_valve_adapt_status'
action_id: 'ADOPT_BURO'
switch: 'switch.thermostat_buro_valve_adapt_process'
schlafzimmer:
sensor: 'sensor.thermostat_schlafzimmer_valve_adapt_status'
action_id: 'ADOPT_SCHLAFZIMMER'
switch: 'switch.thermostat_schlafzimmer_valve_adapt_process'
gastezimmer:
sensor: 'sensor.thermostat_gastezimmer_valve_adapt_status'
action_id: 'ADOPT_GASTEZIMMER'
switch: 'switch.thermostat_gastezimmer_valve_adapt_process'
vorzimmer:
sensor: 'sensor.thermostat_vorzimmer_valve_adapt_status'
action_id: 'ADOPT_VORZIMMER'
switch: 'switch.thermostat_vorzimmer_valve_adapt_process'
wohnzimmerfenster:
sensor: 'sensor.thermostat_wohnzimmerfenster_valve_adapt_status'
action_id: 'ADOPT_WOHNZIMMERFENSTER'
switch: 'switch.thermostat_wohnzimmerfenster_valve_adapt_process'
wohnzimmertur:
sensor: 'sensor.thermostat_wohnzimmertur_valve_adapt_status'
action_id: 'ADOPT_WOHNZIMMERTUR'
switch: 'switch.thermostat_wohnzimmertur_valve_adapt_process'
- alias: "Send Notification"
service: notify.mobile_app_iphone_von_franz
data:
title: Thermostat Alert
message: >
{% set problem_thermostats = thermostats %}
{% for key, data in problem_thermostats.items() %}
{% if states(data.sensor) != 'success' %}
- {{ key.capitalize() }}: {{ states(data.sensor) }}
{% endif %}
{% endfor %}
data:
actions:
{% for key, data in thermostats.items() %}
{% if states(data.sensor) != 'success' %}
- action: "{{ data.action_id }}"
title: "Start {{ key.capitalize() }} Adoption"
{% endif %}
{% endfor %}
- alias: "Wait for Button Response"
wait_for_trigger:
{% for key, data in thermostats.items() %}
{% if states(data.sensor) != 'success' %}
- platform: event
event_type: mobile_app_notification_action
event_data:
action: "{{ data.action_id }}"
{% endif %}
{% endfor %}
- alias: "Perform the Selected Action"
choose:
{% for key, data in thermostats.items() %}
{% if states(data.sensor) != 'success' %}
- conditions: "{{ wait.trigger.event.data.action == data.action_id }}"
sequence:
- service: switch.turn_on
target:
entity_id: "{{ data.switch }}"
{% endif %}
{% endfor %}
Hope somebody can help me with it. (If I do not make it dynamically (so I always see all thermostats status and all buttons) I made it already work… (Y)