Hi, i have setup an automation with 2 or more switches and lights to turn on/off using “platform: state”.
I would like to combine this with “if, this, else” but i have some trouble with the yaml code.
My goal is to automatically turn on the lights at 50% after sundown/before sunset when one of the switches are used.
This is the yaml without dimming the lights. I use this for all our lights/switches and it works perfect.
alias: test
description: ""
trigger:
- platform: state
entity_id:
- light.testlamp
- switch.sonoff_10008c4c7a_1
from: "on"
to: "off"
- platform: state
entity_id:
- light.testlamp
- switch.sonoff_10008c4c7a_1
from: "off"
to: "on"
condition: []
action:
- service: switch.turn_{{ trigger.to_state.state }}
target:
entity_id:
- switch.sonoff_10008c4c7a_1
- service: light.turn_{{ trigger.to_state.state }}
target:
entity_id: light.testlamp
mode: restart
I tried this yaml code but that doesn’t work:
alias: test
description: ""
trigger:
- platform: state
entity_id:
- light.testlamp
- switch.sonoff_10008c4c7a_1
from: "on"
to: "off"
- platform: state
entity_id:
- light.testlamp
- switch.sonoff_10008c4c7a_1
from: "off"
to: "on"
condition: []
action:
- if:
- condition: time
after: "23:00:00"
before: "07:00:00"
then:
- service: switch.turn_{{ trigger.to_state.state }}
target:
entity_id:
- switch.sonoff_10008c4c7a_1
- service: light.turn_{{ trigger.to_state.state }}
data:
brightness_pct: 50
target:
device_id: 3b4720b2c4952ac4747d9b4b97682e62
else:
- service: switch.turn_{{ trigger.to_state.state }}
target:
entity_id:
- switch.sonoff_10008c4c7a_1
- service: light.turn_{{ trigger.to_state.state }}
data:
brightness_pct: 100
target:
device_id: 3b4720b2c4952ac4747d9b4b97682e62
mode: restart
Can someone point me in the right direction here please?