PilaScat
(Filippo Scatigna)
1
Tried this but it doesn’t work:
alias: Global - Renna
description: ""
trigger:
- platform: sun
event: sunrise
- platform: sun
event: sunset
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.platform == 'sun' and trigger.event == 'sunset') }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.sonoff_presa_smart
data: {}
- conditions:
- condition: template
value_template: "{{ trigger.platform == 'sun' and trigger.event == 'sunrise') }}"
sequence:
- service: switch.turn_off
target:
entity_id: switch.sonoff_presa_smart
data: {}
default: []
mode: single
{{ states ('sun.sun' == 'below_horizon' }}
{{ states ('sun.sun' == 'above_horizon' }}
PilaScat
(Filippo Scatigna)
3
Invalid template:
alias: Global - Renna
description: ""
trigger:
- platform: sun
event: sunrise
- platform: sun
event: sunset
condition: []
action:
- choose:
- conditions:
- condition: template
value_template: "{{ states ('sun.sun' == 'below_horizon' }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.sonoff_presa_smart
data: {}
- conditions:
- condition: template
value_template: "{{ states ('sun.sun' == 'above_horizon' }}"
sequence:
- service: switch.turn_off
target:
entity_id: switch.sonoff_presa_smart
data: {}
default: []
mode: single
{{ states('sun.sun' == 'below_horizon') }}
{{ states('sun.sun' == 'above_horizon') }}
123
(Taras)
5
alias: Global - Renna
description: ""
trigger:
- id: 'on'
platform: sun
event: sunrise
- id: 'off'
platform: sun
event: sunset
condition: []
action:
- service: 'switch.turn_{{ trigger.id }}'
target:
entity_id: switch.sonoff_presa_smart
mode: single
2 Likes
Yep…my bad…bracket wrong
{{ states('sun.sun') == 'below_horizon' }}
EDIT: as often usual … @123 has great short versions
Tinkerer
(aka DubhAd on GitHub)
7
And to riff on Taras’ very compact solution:
alias: Global - Renna
description: ""
trigger:
- platform: state
entity_id: sun.sun
to: ~
action:
- service: "switch.turn_{{ 'off' if is_state('sun.sun','above_horizon') else 'on' }}"
target:
entity_id: switch.sonoff_presa_smart
mode: single
1 Like
123
(Taras)
9
And a slightly shorter riff on Tinkerer’s riff
alias: Global - Renna
description: ""
trigger:
- platform: state
entity_id: sun.sun
to: ~
action:
- service: "switch.turn_{{ iif('above' in trigger.to_state.state, 'off', 'on') }}"
target:
entity_id: switch.sonoff_presa_smart
mode: single
1 Like