diff --git a/blueprints/automation/wd-close-weather-notification.yaml b/blueprints/automation/wd-close-weather-notification.yaml index f4152a5..3b59b0f 100644 --- a/blueprints/automation/wd-close-weather-notification.yaml +++ b/blueprints/automation/wd-close-weather-notification.yaml @@ -72,7 +72,7 @@ trigger: - platform: numeric_state entity_id: !input temperature_sensor below: !input temp_below - + condition: - condition: state entity_id: !input openings @@ -80,27 +80,33 @@ condition: action: - variables: - selected_openings: !input openings - selected_temp_sensor: !input temperature_sensor - selected_weather: !input weather_sensor - selected_notify_target: !input notify_target - selected_custom_message: !input custom_message open_entities: > - {{ states | selectattr('entity_id','in',selected_openings) | selectattr('state','eq','on') | map(attribute='attributes.friendly_name') | list }} - trigger_state: > - {% if trigger.platform in ['numeric_state','state'] %} - {{ trigger.to_state.state }} + {% set openings = states.binary_sensor | selectattr('entity_id', 'in', !input openings) | selectattr('state', 'eq', 'on') | map(attribute='attributes.friendly_name') | list %} + {% if openings | length > 0 %} + {{ openings }} {% else %} - unknown + [] {% endif %} + - if: "{{ open_entities | length > 0 }}" + then: + - service: notify.notify + data: + target: !input notify_target + message: > + {% set trigger_state = 'Unknown' %} + {% if trigger.platform == 'numeric_state' %} + {% if trigger.above is defined %} + {% set trigger_state = 'Temperature > ' + trigger.above | string %} + {% elif trigger.below is defined %} + {% set trigger_state = 'Temperature < ' + trigger.below | string %} + {% endif %} + {% elif trigger.platform == 'state' %} + {% set trigger_state = trigger.to_state.state %} + {% endif %} - - service: notify.notify - data: - target: "{{ selected_notify_target }}" - message: > - {% for entity_name in open_entities %} - {{ selected_custom_message - | replace('{{ entity_name }}', entity_name) - | replace('{{ trigger_state }}', trigger_state) - }} - {% endfor %} \ No newline at end of file + {% set msg = !input custom_message | replace('{{ trigger_state }}', trigger_state) %} + {% set message_parts = [] %} + {% for entity_name in open_entities %} + {% set message_parts = message_parts + [msg | replace('{{ entity_name }}', entity_name)] %} + {% endfor %} + {{ message_parts | join("\n") }} \ No newline at end of file