I am planning an automation for my window blinds. Each of my windows have blinds controlled by HA as well as a sensor to report if the window is closed or open.
New I like to do the following:
If I open the window (because I need some fresh air) and the blinds are lower than a defined level, the blinds shall roll up until this level is reached (maybe with hysteresis).
When I now close the window again, the blinds shall roll back down to their previous level.
In pseudocode, it would look like this:
If(window_1 gets opened)
{
if(actual position is lower than x)
{
remember actual position x
roll blinds up to x
}
}
And the other way:
if(window_1 gets closed)
{
recall previous position
if(window had been lower before)
{
roll blinds back down until previous position
}
}
The logic is clear, but how could this be solved in HA? How can I remember a state/value and recall it later?
Great, thank you! I would have wondered, Iād been the first one who wanted to do such a thing .
I will read through it and report back my results.
Thanks again!
EDIT:
ok, if I understand it correctly, you just take an āinput_numberā component to store a value? Well, this isā¦ a really smart idea! Maybe this is a just too obvious, so that I didnāt think about this by myself! In Germany we say āYou donāt see the forest because of all the trees.ā
Ok, now I have implemented two automations: one for opening the cover to let in some fresh air and one to close it again after refreshment.
For this I added an āinput_numberā for each window to store the value of the actual position before opening it.
I also added an āinput_numberā component to adjust the position to where the covers should go when the window gets opened.
Now, Iād highly appreciate, if someone could have a look at my ācodeā if it is formatted correctly. Maybe I need conversions or something like that?
- id: '834611532639'
alias: Open blinds when window gets opened
trigger:
- entity_id: binary_sensor.living_room
from: open
platform: state
to: closed
- entity_id: binary_sensor.dinning_room
from: open
platform: state
to: closed
- (many more window sensors here)
condition:
- condition: numeric state
entity_id: cover.{{trigger.entity_id.split('.')[1]}}.position
below: input_number.fresh_air.value
action:
- service: input_number.set_value
data:
entity_id: input_number.{{trigger.entity_id.split('.')[1]}}
value: cover.{{trigger.entity_id.split('.')[1]}}.position
- service: cover.set_cover_position
data:
entity_id: cover.{{trigger.entity_id.split('.')[1]}}
position: input_number.fresh_air.value
- id: '834611531604'
alias: Close Blinds when window gets closed
trigger:
- entity_id: binary_sensor.living_room
from: open
platform: state
to: closed
- entity_id: binary_sensor.dinning_room
from: open
platform: state
to: closed
- (many more window sensors here)
condition:
- condition: numeric state
entity_id: input_number.{{trigger.entity_id.split('.')[1]}}
below: cover.{{trigger.entity_id.split('.')[1]}}.position
action:
- service: cover.set_cover_position
data:
entity_id: cover.{{trigger.entity_id.split('.')[1]}}
position: input_number.{{trigger.entity_id.split('.')[1]}}.value
- service: input_number.set_value
data:
entity_id: input_number.{{trigger.entity_id.split('.')[1]}}
value: 0
Especially the parts where I copy the actual position into the input_number and back are where I am not that sure about the correct formattingā¦
Jojo,
Itās a bit difficult to see how this works as Iām not sure of the values and what represents your (preferred) up position and what a typical down position is (in relation to your typical input_number.fresh_air.value is).
Also your both your triggers go from open to closed, I would have thought one would be the other way
Can you give us complete entity names (typical of each window) ?
Finally, your first code :-
@Mutt
thanks a ton, that you took some time to take a look at my config. You are completely right about the wrong parts in my config. But in the meantime, I was changing and actually fixing a lot of things and now it kind of works.
At the moment, I try to figure out, how to have my automations ādynamicā, so that there are multiple triggers (different window contacts) that trigger all the same automation, but only for that specific window, that was opened/closed. But this is another story (Dynamic Automation for multiple components?).
Thanks to you, I know now how to use input_number components as āvariablesā to store values (which is essential for my automation system) .
Jojo,
Iām pleased that you now have something that works even if you want to improve upon it further.
Could you post the code as it now stands, that will help anyone else with a similar issue find your code and have a good starting point from which to work for them.
If you do manage to polish it up to a dynamic automation, then I would request that you again return to this thread and post the updated code for the benefit of the community
Oh ! I also noted the - id: ā834611532639ā so this āwasā generated by the automation editor (nothing wrong with that, but you can tidy up afterwards AND note that this will purge your file of ALL comments - dangerous when you are troubleshooting later or worse still adapt āthisā to āthatā but you donāt understand/remember this āwidgetā), you can, if it helps you (t certainly does for me), change that to - id: auto_blind2lvngrm_openwthwndw or something more memorable so that you will know what it refers to in the future when you come across a reference to it elsewhere in the system (all clues help) especially when your system grows ; - )
Finally, you can ālikeā a response that has helped you, this will make the thread more attractive and it helps your helpers too.
Cheers
Mutt
@Mutt
alright, thanks for the hints!
It is correct that the automation editor does not generate ābeautifulā code. I am thinking about to just not use it at all, because of its limitations and the fact, that it deletes comments, etc.
About the code: well, there is totally no problem to post it. I already did in the thread a refered to above. I just have not done it here, because the code has nothing to do with the original topic of this thread (āhow to store values in a variableā).
The initial problem has been solved here, thats why I marked you post as solution .
Jojo,
I almost agree but think about what you were searching for and when you didnāt find it, you asked a question with a title that summarised your issue.
The next person to the site with a similar question may well find this thread and not the other one. Cross linking and quoting is good for everyone ; - )
Have a great Christmas
Mutt