I created an automation using the “Automation editor” in the configure menu.
The automation is to turn on a light when I get home if the sun as set, and then turn off 5 minutes later. The code in the automations.yaml is as follows
- id: '1522375322401'
alias: front lights
trigger:
- entity_id: device_tracker.jasonphone, device_tracker.shannonphone
from: not_home
platform: state
to: home
condition:
- after: sunset
condition: sun
action:
- data:
payload: 'ON'
topic: cmnd/sonoff-front-out/POWER
service: mqtt.publish
- delay: 00:05:00
- data:
payload: 'OFF'
topic: cmnd/sonoff-front-out/POWER
service: mqtt.publish
I realized later that if the light was already on and it detected me getting home, it would turn off the light after 5 minutes. (dont want this)
what I want to do is add a condition “if the light is off” so that if the light is already on it wont run the automation.
I tried adding it in the automation editor (the resulting code is below).
once I’ve added the second condition though, the automation never runs at all… been puzzling over this for a number of weeks.
- id: '1522375322401'
alias: front lights
trigger:
- entity_id: device_tracker.jasonphone, device_tracker.shannonphone
from: not_home
platform: state
to: home
condition:
- after: sunset
condition: sun
- condition: state
entity_id: switch.frontoutlight
state: 'OFF'
action:
- data:
payload: 'ON'
topic: cmnd/sonoff-front-out/POWER
service: mqtt.publish
- delay: 00:05:00
- data:
payload: 'OFF'
topic: cmnd/sonoff-front-out/POWER
service: mqtt.publish
the switch is configured as the following in the config.yaml
switch:
platform: mqtt
name: frontoutlight
friendly_name: Front Outside Lights
command_topic: “cmnd/sonoff-front-out/power”
state_topic: “stat/sonoff-front-out/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true
any help would be appreciated.