**I went down a rabbit hole on this one. **
Wanted a Message box pop up if AC is on and a door or window was left open for a few minutes.
First I have a group for all my door and window sensors to have a sensor available if one of them are open.
Then I created a sensor to show a list of what is open when on.
- sensors:
what_is_open:
friendly_name: "what is open"
unique_id: whatisopen
value_template: >
"{{expand('binary_sensor.doors_and_windows') | selectattr('state', 'eq', 'on')| map(attribute='name') | list | join(' & ') }}"
But I could not get it to work when referencing the sensor within the payload of the automation. Maybe someone can explain to how if possible?
It works fine after I just added the template code directly into the action payload in the automation like below.
**Iām breaking this down in steps **
FULL AUTOMATION CODE AT BOTTOM
TRIGGERS: When
This part below will trigger the start of automation when the AC switches to COOLING action mode, OR the group sensor is ON.
trigger:
- platform: state
entity_id:
- climate.house_a_c
attribute: hvac_action
to: cooling
for:
hours: 0
minutes: 0
seconds: 5
enabled: true
- platform: state
entity_id:
- binary_sensor.doors_and_windows
to: "on"
for:
hours: 0
minutes: 1
seconds: 30
from: "off"
CONDITIONS: And if
**This part below checks to be sure ** IF cooling action is COOLING and IF any door or window is already open before continuing the automation after triggers above.
Just some extra redundancy to check if windows are for sure open and AC is cooling before any action.
- condition: and
conditions:
- condition: state
entity_id: climate.house_a_c
attribute: hvac_action
state: cooling
- condition: state
entity_id: binary_sensor.doors_and_windows
state: "on"
ACTIONS: Then do
This part below will Turn on the back light to all plates.
service: mqtt.publish
data:
qos: 0
topic: hasp/plates/command/backlight
payload: "on"
alias: TURN ON BACK LIGHT to all plates
ACTION PAYLOAD For POP UP
service: mqtt.publish
data:
qos: 0
topic: hasp/plates/command/jsonl
payload: >-
{"page":0,"id":75,"obj":"msgbox","bg_color":"white","text_color":"Red","text":"AC
is Cooling AND {{expand('binary_sensor.doors_and_windows') |
selectattr('state', 'eq', 'on')| map(attribute='name') | list | join(' & ')
}}
\uF11D ARE OPEN \uF11D ","options":["Close"]}
enabled: true
alias: publish to ID75 popup warning with LIST of sensors open to all plates
*Note the ID 75 is the message box ID so be sure to have a unique ID# so it will not overwrite any other message box you have already. *
and to use the same ID# for your DELETE action.
This part Below is at the end of the automation will delete the Message box after ALL doors and windows are closed. (be sure to use the same ID# as your message box above.)
AUTOMATICALLY CLOSE/DELETE MESSAGE BOX
Wait for something to close trigger
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.doors_and_windows
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 0
timeout:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
continue_on_timeout: true
enabled: true
alias: wait for sensor to show all closed
Delete Message box.
- service: mqtt.publish
data:
topic: hasp/plates/command/p0b75.delete
alias: delete Message box ID75
FULL yaml to copy and paste into a new automation.
alias: popup ac is on something open
description: ""
trigger:
- platform: state
entity_id:
- climate.house_a_c
attribute: hvac_action
to: cooling
for:
hours: 0
minutes: 0
seconds: 5
enabled: true
- platform: state
entity_id:
- binary_sensor.doors_and_windows
to: "on"
for:
hours: 0
minutes: 1
seconds: 30
from: "off"
condition:
- condition: and
conditions:
- condition: state
entity_id: climate.house_a_c
attribute: hvac_action
state: cooling
- condition: state
entity_id: binary_sensor.doors_and_windows
state: "on"
action:
- service: mqtt.publish
data:
qos: 0
topic: hasp/plates/command/backlight
payload: "on"
alias: TURN ON BACK LIGHT to all plates
- service: mqtt.publish
data:
qos: 0
topic: hasp/plates/command/jsonl
payload: >-
{"page":0,"id":75,"obj":"msgbox","bg_color":"white","text_color":"Red","text":"AC
is Cooling AND {{expand('binary_sensor.doors_and_windows') |
selectattr('state', 'eq', 'on')| map(attribute='name') | list | join(' &
') }}
\uF11D ARE OPEN \uF11D ","options":["Close"]}
enabled: true
alias: publish to ID75 popup warning with LIST of sensors open to all plates
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.doors_and_windows
from: "on"
to: "off"
for:
hours: 0
minutes: 0
seconds: 0
timeout:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
continue_on_timeout: true
enabled: true
alias: wait for sensor to show all closed
- service: mqtt.publish
data:
topic: hasp/plates/command/p0b75.delete
alias: delete Message box ID75
enabled: true
mode: queued
max: 10
More of my Openhasp here