Makis
(Makis)
1
HI all
I am trying to add a simple automation but it is not working.
the trigger works but the condition isn’t. I tried
not connected
<not connected>
<not_connected>
What is going wrong?
alias: trigger when connected to wifi
trigger:
- platform: state
entity_id: sensor.makis_smartphone_wifi_connection
to: "mkDevices"
- platform: state
entity_id: sensor.makis_smartphone_wifi_connection
to: "COSMOTE-CBA6C4"
condition:
- condition: state
entity_id: sensor.makis_smartphone_wifi_connection
state: "<not connected>"
for: "00:05:00"
action:
- service: switch.toggle
target:
entity_id: switch.sonoff_100082f960
mode: single```
tom_l
2
<not connected>
that’s the one it should be. However you are triggering on it being connected, so the condition will never be true.
Trigger occurs first then conditions are checked.
Makis
(Makis)
3
you are right
probably I need a sensor/helper for the condition?
or could I change the condition to trigger and vise versa?
I prefer not to use extra sensors if not absolutely necessary.
tom_l
4
You haven’t said what you want the automation to do.
Makis
(Makis)
5
I need to toggle the switch the moment my phone connects to my wifi network. without the condition although it triggers more often than i need.
the minutes will be more the 20 in the end. I have it on 5 to test it only
tom_l
6
If you only want the automation to trigger every 20 minutes at most try this:
alias: trigger when connected to wifi
trigger:
- platform: state
entity_id: sensor.makis_smartphone_wifi_connection
to: "mkDevices"
- platform: state
entity_id: sensor.makis_smartphone_wifi_connection
to: "COSMOTE-CBA6C4"
condition:
- condition: template
value_template: "{{ now() - this.attributes.last_triggered|default(as_datetime(0),1) > timedelta(minutes=20) }}"
action:
- service: switch.toggle
target:
entity_id: switch.sonoff_100082f960
mode: single
Makis
(Makis)
7
yes, it worked!
Thank you Tom
1 Like