since I’m new to HA and also Jinja2 my thoughts on the following issue are based on how I would realise it with PHP.
I’d like to built an automation that controls an rgb bulb that reminds me on an open window after several timers have passed. Due to the point that I don’t wanna set specific values for rgb and brightness these attributes are variables.
So the logic behind my intended automation should be:
retrieve current state and attributes of the lamp and store these information in an array to reset the lamp later on:
Thanks for the hint but as far as I understand scenes create a snapshot for a given status. In my case I would need to create a scene of that actual moment within an automation instead of calling a scene that has fixed values.
To be more precise here is some explanation of the logic:
the bulb can be either on or off → when its on than it can have a color and brightness setting whatever it was set before depending from the mood and playing around - so this is not fixed.
in a first step the window is open for more than 10 minutes and the color and brightness of the bulb changes to blue and decreases brightness - all some fixed settings.
in the second step there is a condition for the bulb either the window will be closed and the state/settings will be reset to the initial one which I don’t really know → as mentioned in no.1
or
after further 10mins of an open window the color will change to red and again increase the brightness to some other fixed settings.
As long as the window is still open the bulb remains with the red light and will be reset to no.1 after the window has been closed.
As far as I understood a scene has to be fixed, or am I wrong and there is another way to go for this?
jchh
(my username is my initials (and my first name isn't John))
4
That’s what this does. You can create an ad-hoc scene at that point in time. Here is a script that does the same thing (it creates an adhoc scene called front_snapshot, makes my porch light bright and then starts a timer):
script:
porch_light_bright:
alias: "Porch light bright-white for 3 mins"
sequence:
- service: scene.create # save light to scene
data:
scene_id: front_snapshot
snapshot_entities:
- light.porch_colour
- service: light.turn_on # turn on light
data:
entity_id: light.porch_colour
transition: 1
brightness_pct: 100
rgb_color: [255, 255, 255]
- service: timer.start # start timer
target:
entity_id: timer.porch_light
mode: single
icon: hass:coach-lamp
I have an automation that calls that script when motion is detected. The same automation does the following after the timer has cleared:
automation:
[...]
action:
- if:
- condition: trigger
id: 'timer_finished'
then:
- service: scene.turn_on # revert light to original scene
data:
entity_id: scene.front_snapshot
I do it this way as I call that script from other automatons as well and the timer allows the automation to not be actively waiting for a long period of time.
After tinkering around all night long and even trying to implement scenes I’m not really happy with the result.
The following code works almost fine except one little issue. For the case that the bulb initially is on everything is fine. Just in case that the bulb is initially off it won’t create the right scene.
In example, like explained in no.1 from my last post, the logic should be:
light: can be either on or off, random rgb code and brightness
case 1 (light is on): open window for 10mins - change rgb color to light blue and increase brightness (if window is closed reset values) - after 20mins change color to red and increase brightness (if window is closed reset values).
case 2 (light is off) : open window for 10mins - turn light on to blue and increase brightness (if window is closed reset values and turn off) - after 20mins change color to red and increase brightness (if window is closed reset values and turn off)
works fine for the first case when the light is on. In the second case when the light should be turned off it doesn’t set the value for rgb and brightness correctly. No matter if the window is being closed within the first 20min or afterwards - after calling the initial scene when the window is being closed it turns off with the last information either blue or red. When turning the light manually back on its either blue or red instead of the initial color and brightness.
jchh
(my username is my initials (and my first name isn't John))
7
The scene.create & scene.turn_on work perfectly for me with the light off scenario. I have just rechecked it before posting this.
Question: Are you triggering after 10 & 20 secs for the purpose of testing? If so, can you change to 1 min and 2mins and try again?
Yes, that’s for testing purposes only. I just changed them to 1 and 2 mins but with no change. Still the same result.
I’m using:
Home Assistant 2023.2.5 Supervisor 2023.01.1 Operating System 9.5 Frontend 20230202.0 - latest
running with SkyConnect as Coordinator in ZHA integration. The bulb is a LIDL/Livarno E14 RGB model HG08131B Version 10/2021.
jchh
(my username is my initials (and my first name isn't John))
9