Greetings,
I’ve got a light in a room and I would like to turn it on, triggered by a motion sensor. This was more or less simple.
Now I would like to adjust the brightness based on the time:
16h-02h: 100%
02h-05h: 50%
05h-09h: 100%
I’ve created three automations and it works … but it feels somehow clumsy.
Is there a better way to create a sensor or similar to get it done?
Thanks in advance,
Fridolin
finity
November 17, 2020, 4:17am
2
look into the “choose:” option for the automation. It’s in the script documentation on the HA site.
basically you can set the automation to run different actions in the same automation based on different conditions.
1 Like
Thanks a lot. I’ve been using the UI based wizard and there having if/elseif/…/then is not supported …or at least I cannot see something like that.
But the script syntax is allowing that, so I’ll give that a try.
finity
November 17, 2020, 4:05pm
4
So you are saying that the “choose:” function isn’t an option in the automation UI editor but it is in the script UI editor?
That’s one of the reasons I never use the UI editors. IMHO (along with many others), it’s always better to do it by hand.
You will learn a lot more that way and you don’t have to worry about the inherent limitations and idiosyncrasies of those editors.
I’ve managed to get to what I wanted by directly adding the code to the automations.yaml:
trigger:
- platform: state
entity_id: binary_sensor.0x00158d000450bc35_occupancy
to: 'on'
action:
- choose:
- conditions:
- condition: time
after: '16:00'
before: 02:00
sequence:
- service: homeassistant.turn_on
data:
transition: 2
brightness_pct: 100
entity_id: light.0x001788010940bf8d_light
- conditions:
- condition: time
after: 02:00
before: 05:30
sequence:
- service: homeassistant.turn_on
data:
transition: 2
brightness_pct: 15
entity_id: light.0x001788010940bf8d_light
- conditions:
- condition: time
after: 05:30
before: 09:00
sequence:
- service: homeassistant.turn_on
data:
transition: 2
brightness_pct: 100
entity_id: light.0x001788010940bf8d_light
default:
- service: homeassistant.turn_off
entity_id: light.0x001788010940bf8d_light
data:
transition: 2
mode: single
I guess, the service execution can be implemented in a more elegant way, but at least I reduced the amount of single Automations.
btw: after manually adapting the yaml, the UI is also showing ‘options’. I don’t know, how they’ve gotten there, but now it is possible to add even more options using the wizard.