Requirement: Automation triggers if “state” is set “true” twice in a row.
I.E. Condition checks if remote ON switch (external to HASS) has been pressed twice (I.E. On then On again, without a Off in-between).
Current thinking is below, which does not work, as condition is always true as trigger and condition monitor the same state, so the condition is always true.
- alias: Kitchen Extractor Enable Auto Off
trigger:
platform: state
entity_id: switch.kitchen_extractor_fan # Wireless 433 switch, picked up by RFLink
state: 'on'
condition:
# Only scrtipstart if the fan is already on
condition: state
entity_id: switch.kitchen_extractor_fan
state: 'on'
action:
service: script.turn_on
data:
entity_id: script.kitchen_extractor_timer
This is not making a lot of sense to me. How do you turn on the switch switch.kitchen_extractor_fan if it is already on? The automation will not trigger because there is no state change when the switch is already on.
Yes I just tested it and if the “switch.kitchen_extractor_fan” state is already “on” then the automation will not run at all.
I need to change the logic to, how about:
If “switch.kitchen_extractor_fan” == OFF and “script.kitchen_extractor_timer” ==OFF
then: switch.kitchen_extractor_fan = ON
else if “switch.kitchen_extractor_fan” == ON and “script.kitchen_extractor_timer” ==OFF
then “script.kitchen_extractor_timer” == ON
Kinda sounds like something I am doing with my mailbox alerts. I want the sensor on the mailbox to trip a notification when it is opened by the mail carrier putting mail in the box. But I don’t want a second notification when I open the mailbox to retrieve it.
So I use an input boolean to track the state like this:
Input Boolean:
mailbox_switch:
name: Toggle Mailbox Automation
initial: off
icon: mdi:email
Automation for mail alert (home version; there is also one for notifications when I am away):
# Notify when Mail has arrived - Home
- alias: 'Mail Alert Home'
trigger:
platform: state
entity_id: binary_sensor.mailbox_opened
from: 'off'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.mailbox_switch
state: 'off'
- condition: state
entity_id: device_tracker.rpitera_rpitera
state: 'home'
action:
- service: tts.google_say
entity_id: media_player.living_room_home
data:
message: 'Pardon the interruption, Robert but the mail has been delivered.'
- service: input_boolean.turn_on
entity_id: input_boolean.mailbox_switch
Reset automation accounting for me opening the box:
# Works with Mail Alert routines, sets flag to prevent new notification
# when retrieving the mail
- alias: 'Mail Retrieval'
trigger:
platform: state
entity_id: binary_sensor.mailbox_opened
from: 'off'
condition:
condition: state
entity_id: input_boolean.mailbox_switch
state: 'on'
action:
service: input_boolean.turn_off
entity_id: input_boolean.mailbox_switch
Hi,
I see this tread is some months old, so meaby you already figured this out.
But I have a 433 MHz switch that do different things if it is pressed twice.