I’m calling climate.toggle on my mini split and it always turns on to heat regardless of what the previous mode was (ie cooling or fan_only). Is there a way to make it turn on to the previous mode with a simple toggle button?
Make a script for toggling off that reads the state and then store it in a helper and then turns off the climate device.
Make another script for toggling on that reads the helper and then turn on the climate device and make a service call to set the mode that was retrieved from the helper.
You can then make a template switch and then call that in the tap_action.
You could create a trigger-based template sensor to store the previous state of the climate entity. A trigger-based template sensor essentially is a combination of an automation and a helper, with the added benefit that the helper is not editable from the UI.
If that is your first template entity in YAML then you’ll need to reboot HA for it to take effect. If not, make sure to not duplicate the template: heading, and then in developer tools → YAML you can click the button to reload template entities.
Then you can create a script that sets the HVAC based on the state of that new template entity:
Would it not be better to use not_to: ??
The current setup would not store the state if the previous state is unavailable or unknown, even though it is a state on the actual climate device. It might store unavailable and unknown though, because it might be coming from a state on the actual climate device.
I never want this sensor to store either unavailable or unknown, and it always stores the state the climate entity comes from, so I never want to trigger when the climate entity comes fromunavailable or unknown.
Note that this is the previous state of the climate entity: trigger.from_state.state
It depends on the hardware and the integration you use. Some do have that behavior. Other climate entities don’t support being turned on & off. Some support being turned off, but don’t support being turned on without specifying the mode. For example on my Nest thermostat, when I physically interact with it, I can select modes of “Off, Heat, Cool, Heat & Cool”. There is no “on” state that I can choose. When I interact with it programmatically via HA, the same behavior applies: I have to choose the mode; I can’t simply tell it to turn “on”. However the integration I use will remember the state it was in prior to being off, so the toggle command will restore that previous state.
You can do pretty much anything in ESPHome. Best to start a new post in that category.
I went a slightly different path:
At the core, what’s driving the climate state shouldn’t necessarily be it’s previous state but rather the temperature. So I just made an automation that runs a basic if then on the internal temp of the room to decide what you likely want to do. The only downside I see for this is when I want to only use the fan mode instead of heat or cool. I’ll have to deal with that when it gets a bit warmer.