Restore HVAC mode when window closed

I have integrated Gree climate and made automation when window is opened (Binary sensor), clima is turned off. When window is closed again, I would like to restore HVAC_mode. I understand that I need to write down HVAC_mode at the time when automation is trigered by opening window. Where I can log it, and how?
How to read this data and set HVAC_mode agan when window is closed?

You could create a scene on the fly, something like the following:

action
  service: scene.create
  data:
    scene_id: temp_hvac # (or similar)
    snapshot_entities:
    - climate.hvac_gree # (what every your entity is called)

This will (depending on your climate setup and forgive me as I dont know) stored the complete state of the entity and all its underlying attributes.

And then when you want to set your HVAC back simply call the scene like:

service: scene.turn_on
data:
target:
  entity_id: temp_hvac

I have however found that with some setups this either dosent work as expected or causes errors in the logs as some attributes cant be called directly.

So the other way I can think of is to make a text input helper and call it something like ‘gree_climate_state’ for example and then add something like this to the initial automation:

service: input_text.set_value
data:
  value: '{{(state_attr(''climate.hvac_gree'', ''hvac_mode'') | string )}}'  # for example
target:
  entity_id: input_text.gree_climate_state

Then when you want to set it back, something like this maybe:

service: climate.set_hvac_mode
data:
  hvac_mode: {{states('input_text.bedtime_reminders')}}
target:
  entity_id: climate.hvac_gree

You will obviously need to change to above to match up with your own entities, states and attributes for example. If in doubt check them out in developer tools states and then test them out in developer tools template section.

1 Like

Thanks rossk, option with scene creation works well.

1 Like

Perfect, glad it worked out for you, for the benefit of others would you be so kind as to mark my post as the solution, as this aids in others finding solutions to similar questions.