I’m brand new to creating automations as I mostly want to “be in control”. But I really wanted to automate the bathroom lamp to turn on at different settings depending on the time of day. While this was possible by creating simple timed rules in different automations I quickly got snugged up in trying to create one automation to rule them all. Addictions and such.
I’ve been trying to learn how to control templates but I seem to have hit a dead end of sorts. The “check configuration” button clears this one for errors which was my first goal. Now I just need to get it to actually launch the scene as well.
- id: bathroom_on
alias: Badrumssensor på
trigger:
- entity_id: binary_sensor.tradfri_motion_sensor
platform: state
to: 'on'
condition:
- condition: state
entity_id: light.yeelight_color2_04cf8c7b5fe9
state: ‘off’
action:
service: scene.turn_on
data_template:
entity_id: >
{%-if now().weekday() in (0,1,2,3,4) and now().hour >=05 and now().hour < 09 () %}
scene.makeup
{% elif now().weekday() in (0,1,2,3,4) and now().hour >=09 and now().hour < 18 %}
scene.daytime_bt
{% elif now().weekday() in (0,1,2,3,4) and now().hour >=18 and now().hour < 05 %}
scene.evening_bt
{%-endif %}
Any suggestions?
The “weekday” thing might go in final configuration as I obviously want them to turn on during the weekend as well.
you have the wrong quote type inside your condition. Notice how the trigger to: 'on' section is red and your state: 'off' section’s quotes look wierd? It’s because you copied that condition from a forum post here. Don’t do that unless it’s formatted properly.
You also had some extra () at the end of your if first if statement.
Your third else if is also a little wrong because it crosses zero. Gotta account for that. But the beauty of that is, you can just use an else statement to cover those hours.
You don’t have a fallback on weekends. Something has to be in the entity_id field when this fires otherwise you’ll get errors. So, move the weekday check to conditions.
(optional) Side note, you can simplify your if statements at the bottom by condensing the time check into a single statement.
Wow!
Thanks. I’ve been searching through different forum posts to try and learn how to do this, but I didn’t think of the quote types. I’ll remember that!
I’ll check your code and see what it amounts to
So this is only used during weekdays?
I’m trying to figure out if that’s actually necessary, or if it would be best just to have them working the same way. Would that be possible just by “removing” the weekday-parameter?
That’s too bad!
I managed to set up the Conbee stick with just a few taps after updating to hass.io (hassOS). IT was a little harder before that but it always worked. Sure you didn’t just get a bad product?
It’s worked like a charm for me since december-17.