Hi,
I’m writing a blueprint to shut off the heat when a window or dor is open. And to restore the heat when the window is closed.
I want to create a scene before turning the heat off with has the name of the entity. That way i can have multiple window open event at the same time. I tried multiple thing in the scene.turn_on to concatenate it but to no avail.
Thank you,
I have updated my blueprint and it does not give me an error when saving. However, when executing i have an error related to upper case in the entity id.
And I do not see how you deal with this in our example.
blueprint:
name: WindowGuard Climate Control
description: This blueprint keeps an eye on your window sensors, taking a snapshot of the environment when they open. When a window is detected as open, it intelligently suspends your heating or cooling systems to conserve energy. Once the window is closed, it restores the previous climate settings.
domain: automation
input:
window_sensor:
name: Window Sensor
description: Select the sensor that monitors your windows to control the heating. **Tip:** If you have multiple window sensors in a room, consider creating a sensor group.
selector:
entity:
filter:
- domain: binary_sensor
- device_class: window
target_climate:
name: Heating Entity
description: Choose the climate entity you want to control (e.g., your heater, AC, or thermostat).
selector:
entity:
filter:
- domain: climate
trigger:
- platform: state
entity_id: !input window_sensor
action:
- variables:
target_climate_var: !input target_climate
- choose:
- conditions:
- condition: state
entity_id: !input window_sensor
state: "on"
sequence:
- service: scene.create
data:
scene_id: "{{ target_climate_var | replace('.', '_') }}_snapshot"
snapshot_entities: !input target_climate
- service: climate.turn_off
data: {}
target:
entity_id: !input target_climate
- conditions:
- condition: state
entity_id: !input window_sensor
state: "off"
sequence:
- service: scene.turn_on
data: {}
target:
entity_id: "scene.{{ target_climate_var | replace('.', '_') }}_snapshot"
It would be more efficient and less prone to error if you did this in the variable section giving it a variable name and using the variable name in the automation instead of generating it multiple times thru the automation.
I also still suggest using a unique name like I suggested above
so it doesn’t crash if 2 copies of the blueprint basecode try to run at the same time.
But I’m glad you got it working.
Hi thanks for the feedback, wen i used the this.context.id, it generated captial letters and the blueprint failed because of that, looking at your automation i dit not figured out how you did not encountered this issue or how to solve it.
blueprint:
name: WindowGuard Climate Control TEST
description: This blueprint keeps an eye on your window sensors, taking a snapshot of the environment when they open. When a window is detected as open, it intelligently suspends your heating or cooling systems to conserve energy. Once the window is closed, it restores the previous climate settings.
source_url: https://gist.github.com/Redblockmasteur/d3602266850016123b55d278f95ba8d4
domain: automation
input:
window_sensor:
name: Window Sensor
description: Select the sensor that monitors your windows to control the heating. **Tip:** If you have multiple window sensors in a room, consider creating a sensor group.
selector:
entity:
filter:
- domain: binary_sensor
- device_class: window
target_climate:
name: Heating Entity
description: Choose the climate entity you want to control (e.g., your heater, AC, or thermostat).
selector:
entity:
filter:
- domain: climate
trigger:
- platform: state
entity_id: !input window_sensor
action:
- variables:
target_climate_var: !input target_climate
my_scene_id: "{{ this.context.id | lower }}_snapshot"
- choose:
- conditions:
- condition: state
entity_id: !input window_sensor
state: "on"
sequence:
- service: scene.create
data:
scene_id: "{{ scene_id }}"
snapshot_entities: !input target_climate
- service: climate.turn_off
data: {}
target:
entity_id: !input target_climate
- conditions:
- condition: state
entity_id: !input window_sensor
state: "off"
sequence:
- service: scene.turn_on
data: {}
target:
entity_id: "scene.{{ scene_id }}"
OK, yes it will.
Guess that is not what you need then.
There is time between on and off… Hmmm
Well, this will get out of sync kind of easy if you manually control the setting at all or a lot of different scenarios. You will have to watch it closely. I also don’t think creating a scene like you are trying to do lives across an HA restart. I would suggest creating a scene in yaml and setting it using that name instead of creating it when you call the blueprint. then it will be there across restarts.
My idea is not going to be what you want, yours is better for this.
Mine is more for grab the scene, do a thing, restore the scene.
Sorry about that.
But you did find a bug in my code I didn’t know was there, so thanks for helping me out.
Thank you for investing your time in addressing my issues. After careful consideration, I’ve decided to stick with the current process. I don’t foresee Home Assistant experiencing a restart during a window open event, especially given their infrequent and short occurrences during the winter. However, I do acknowledge the potential issue you’ve highlighted.
If my input has contributed to uncovering a bug in your code, I’m genuinely pleased to have played a part in that discovery.
I know er were are solved here, but I was just pointed to a new addition to the HA documentation on the subject.
If it doesn’t help you, perhaps it will help someone referring to this thread in the future.
Link to the specific (I think new) section discussing creating scenes on the fly. It mentions the scene_id needs to be lower case… Ha Ha…