Repository navigation
Conversation
The wall panel of a zone controller remembers the target temperature of
every zone for each mode, and sets them again when the mode is changed on
the panel. A mode change over WiFi does not do that: the zones keep the
values of the old mode (seen on a LE60-13/GH). So a mode change from Home
Assistant left every zone at the wrong target temperature.
SetpointMemory in aiogree/setpoint_memory.py keeps the same memory:
- It learns from every poll. A device reports its mode and its target
temperature in one reply, so the two belong together. A value is stored
when the device reported the same mode on the poll before, so a poll in
the middle of a mode change on the panel is not stored under the wrong
mode. Changes made on the panel or in the Gree+ app are learned the
same way.
- Before the climate entity of the ducted unit changes the mode, it reads
the zones again and stores them under the old mode. After the change it
sends the stored values of the new mode. A mode with no stored values
changes nothing.
- It stores the raw columns that hold the target temperature, per device
MAC and mode: {"<zone mac>": {"heat": {"StTem": 3, "StFahFlg": 0}}}.
The raw columns are the same in Celsius and Fahrenheit, so a recalled
value is right in either unit, and the bit brings back a half degree or
a Fahrenheit value exactly. GreeDevice.target_temperature_props and
set_target_temperature_props give the columns the device uses.
The memory has no Home Assistant imports and is covered by tests against
the fake controller. __init__.py keeps it in a Store per config entry
(gree_custom.<entry_id>.setpoints).
The zones of a zone controller remember their target temperature per mode, as the wall panel does. Standalone and VRF units can now do the same, as an opt-in device option, "Remember Target Temperature per Mode" (setpoint_memory, off by default). Suggested by @p-monteiro in RobHofmann#549. - GreeDevice.target_temperature_props already gives SetTem and TemRec for a standalone or VRF unit, because it uses the columns the unit answers. Raw columns are stored, so a unit set to Fahrenheit needs no conversion. - The unit learns from its own polls: mode and target come in one reply. - On a mode change from Home Assistant, SetpointMemory.apply() sets the stored target of the new mode without sending it, so it goes out in the same command as the mode. Nothing is recalled into Auto, where the unit ignores the target temperature. - The option is in the device options form for units with a target temperature, and in the YAML schema. Tested against fakes. This project has no standalone or VRF unit to try it on.
Asked in review: one PR for the memory of every device, and the memory as a device option that is on by default. - setpoint_memory is offered for every device with a target temperature, zones included, and is on by default. The ducted unit of a zone controller has no target of its own, so it gets no option; it recalls the zones that have it on. GreeDevice.has_target_temperature says which devices have one. - Zones always had the memory before. A zone with the option off is now left out of the learning, and of the recall on a mode change. - As asked as well, and already so: the raw columns are stored, so a value comes back right also when the unit was switched between the modes (a new test has 18.5 C come back as 65 F), and a mode without a stored value keeps the current target. The docs, the option text and the YAML example say it is on by default.
The memory of a removed config entry stayed in .storage. It is now removed in async_remove_entry. The memory is also saved when the entry unloads: a delayed save still pending at that point would write the file again after the removal. The module docstring now says a zone stores StFahFlg as well as StTem.
There was a problem hiding this comment.
The idea is good.
Although I'm not keen on having HA-only behaviour partially implemented in the generic aiogree.
device.py adjustments can be made and kept, but I'd like setpoint_memory to be on the HA side of things, probably next to the coordinator.
Alternatively, all logic should be moved to aiogree and only have the behaviour gated by the HA option, in something like changing def set_operation_mode(self, mode: OperationMode) to have a restore_mode_temperature: bool = True which is driven by the option.
But I think the first option is easier.
The memory is Home Assistant behaviour, turned on by a device option, so it now lives next to the coordinator instead of in aiogree. It still imports nothing from Home Assistant. Its tests import the protocol layer through the package path, so the devices and the memory share one copy of the enums. GreeDevice.set_target_temperature_props() is now set_state_props(), a generic setter for raw columns in the device state. Its docstring says the typed setters are the right choice otherwise.
|
@p-monteiro I went with the first option: The second option would have been awkward for zone controllers anyway: a mode change there has to read and set the zones, which are separate The memory itself still imports nothing from HA, so its tests don't need Done in a82257a |
p-monteiro
left a comment
There was a problem hiding this comment.
Looks good. Let's see if @RobHofmann agrees.
RobHofmann
left a comment
There was a problem hiding this comment.
Thanks @Twintop, I tested this on my test unit (a standalone unit, on Home Assistant 2026.11.1), merged onto the current 5.0-dev.
The part you asked about works. Cool at 24 and Heat at 20, then switching from Home Assistant brings back 24 in Cool and 20 in Heat. The store file is written and the log shows no errors. The full suite passes (341), and the PR merges cleanly with #570 to #577.
One bug: climate.set_temperature with a temperature and a mode
A call like climate.set_temperature with temperature: 22 and hvac_mode: cool loses the 22, and the memory stores it under the old mode.
async_set_temperature() sets the temperature in the pending state first, then calls async_set_hvac_mode():
snapshot()readstarget_temperature_props, andDeviceState.get()returns the pending value first. So the 22 is stored under the old mode.apply()then replaces the pending 22 with the stored value of the new mode, so the unit gets that value instead of 22.
On my test unit, with Cool at 24 and Heat at 20, in Heat: the call with 22 and Cool ended at 24 in Cool, and the store held "heat": {"SetTem": 22, "TemRec": 0}.
The same happens through the real service in pytest. This test fails on the PR (the unit ends at 20, and Cool is stored as 22):
async def test_set_temperature_with_a_mode_keeps_the_given_temperature(
hass: HomeAssistant, gree: GreeEnv
) -> None:
"""A temperature given with the mode wins over the remembered one."""
fake = gree.devices[MAC_A]
fake.values.update({"Pow": 1, "Mod": 1, "SetTem": 24, "TemRec": 0, "TemUn": 0})
host = await gree.start_udp(fake)
entry = await add_entry(hass, ["local"], [MAC_A], [host])
coordinator = next(iter(entry.runtime_data.values()))
memory = coordinator.setpoint_memory
async def poll() -> None:
await coordinator.async_refresh()
await hass.async_block_till_done()
# Heat 20 and Cool 24, as set with the remote
fake.values.update({"Mod": 4, "SetTem": 20})
await poll()
await poll()
fake.values.update({"Mod": 1, "SetTem": 24})
await poll()
await poll()
climate = next(
e.entity_id
for e in er.async_entries_for_config_entry(er.async_get(hass), entry.entry_id)
if e.domain == CLIMATE_DOMAIN
)
await hass.services.async_call(
CLIMATE_DOMAIN,
"set_temperature",
{ATTR_ENTITY_ID: climate, ATTR_TEMPERATURE: 22, "hvac_mode": "heat"},
blocking=True,
)
assert (fake.values["Mod"], fake.values["SetTem"]) == (4, 22)
assert memory.data[MAC_A]["cool"]["SetTem"] == 24A possible fix: skip apply() when the caller gives a temperature, or set the temperature after the mode change. Also, snapshot() and learn() should not store values that are still pending.
Smaller points, not blockers
- "The same mode twice in a row" counts listener calls, not polls. One mode change from Home Assistant calls the listeners more than once, so on my test unit a value was stored about 1 s after the change, with no second poll in between. The guard against a mode change in the middle of a poll works, but it is weaker than the docs say.
- The memory also learns while the unit is off: it stored
"auto": {"SetTem": 21, ...}from my unit while it was off. Probably harmless, but you may want to learn only whilePowis 1. - Every mode change from Home Assistant on a standalone unit now does one more full status read before the command. That is fine, just worth knowing.
…eads A temperature given to climate.set_temperature together with a mode was stored under the old mode, and then replaced by the remembered one. The memory now stores only what a device reported, and apply() leaves alone a target that is already set for the command. learn() counted listener calls, so one mode change from Home Assistant could count as two reads. GreeDevice.status_reads now tells a new read from another look at the same one. A standalone or VRF unit no longer learns while it is off. A zone still does, because its Pow is its damper.
|
Thanks for testing it on your unit, and for the test @RobHofmann ! The bug: fixed in f5abaa9. The memory now only stores what the device reported ( Your test is in as you wrote it, in The smaller points:
Full suite on Linux: 345 passed and 1 skipped on the branch, 408 passed and 1 skipped merged with the current |
|
Retested f5abaa9 on my test unit, merged onto the current |
|
@Twintop, a follow-up to my earlier comment. That one covered behaviour only. @p-monteiro and I also looked at the design, and we think the same feature can be built much smaller on the interface The
|
| Addition | Why it is there | What can replace it |
|---|---|---|
target_temperature_props, set_state_props |
Store the raw columns, so a value survives a °C/°F switch | The existing target_temperature and set_target_temperature(). They already handle the bit, the half degree and °F. I round-tripped every raw value from 16 to 30 °C through them: every real target comes back as the same temperature. The only differences are four °F values that come back with the other encoding of the same °F, and 30.5 °C, which is out of range. Storing the unit with the value covers a unit switch. set_state_props is also a raw setter without checks in the generic library, which we would rather not add. |
has_pending_target_temperature |
apply() runs inside async_set_hvac_mode, after async_set_temperature has already set a target |
In async_set_temperature, set the mode first and the temperature after, or skip the recall when a temperature is given. |
status_reads |
learn() hangs on async_add_listener, and listeners fire on every async_update_listeners(), not only after a read |
Pedro's suggestion: the coordinator knows when the state is read, so call learn() once in GreeCoordinator._update_data(), right after fetch_device_status(). Each call is then one real read. Zones have their own coordinators, so the same hook covers them. |
has_target_temperature |
Decide which devices get the option | Close to target_temperature is not None after the bind. Small, so keep it if you like. |
Storage
The Store per entry, the delayed save, the save on unload and async_remove_entry add about 90 lines to __init__.py. The save on unload exists only because of the delayed save. GreeClimate is already a RestoreEntity, so extra_restore_state_data could hold the memory, and Home Assistant saves and removes it with the entity. I have not tried this, and the zones need some thought, because the zone entities would own the data while the ducted unit drives the recall. If that gets awkward, a simple Store without the delayed save is fine too.
What to keep
- Learning from polls. Without it, a target set on the panel or with the remote is only remembered after Home Assistant has left that mode once, and for zones the panel is the main control.
- The read before a mode change, the option per device, and the behaviour you fixed in f5abaa9: a temperature given with the mode wins, and an off unit learns nothing.
setpoint_memory.py can then be a small class that stores and recalls a float per device and mode.
Tests
The climate test that skips below 2026.11 will run soon. The old pytest-homeassistant-custom-component stopped at 2026.10, and its README now points to the new pytest-homeassistant package from Home Assistant core, which has a 2026.11.1 release. The suite passes on it, and I will open a separate PR for the switch. With that in place, one more Home Assistant level test would be good: a change made on the device, then a poll, then the value is stored. Today that path is only tested with learn() called directly.
Thanks for the work so far. The behaviour is right, and this is only about making it easier to maintain.
|
Just to add to the latest comment, I actually don't mind the |
The memory now stores GreeDevice.target_temperature with its unit, and sets it back with set_target_temperature(). Every target in range comes back as the same temperature, and a value stored in the other unit is converted. This removes target_temperature_props, set_state_props, status_reads and has_pending_target_temperature from GreeDevice. Only has_target_temperature stays. GreeCoordinator._update_data() calls learn() after each read, so every call is one new read, without a counter. A temperature given to climate.set_temperature with a mode is now set by the mode change itself, after the read of the old mode, and goes out in the same command. The stored target is only applied when no temperature is given. The climate entity keeps the memory in its restore state, the entity of the ducted unit for its zones. This replaces the Store, its delayed save, the save on unload and async_remove_entry. New tests through Home Assistant: a change on the device is learned from the polls, and the memory is kept over a reload and a restart. They skip below Home Assistant 2026.11, as the set_temperature test does.
# Conflicts: # custom_components/gree_custom/climate.py
The read before a mode change is now a refresh of the coordinators, whose learn() stores the old mode. The zones get their stored targets through their own coordinator, with its IP recovery and follow-up refresh, like any other command. The memory itself does no I/O, so snapshot() and recall() are gone. The option is now on the device whose mode changes: a unit with a target temperature, or the ducted unit of a zone controller for all of its zones, as the wall panel does. GreeDevice is unchanged from 5.0-dev. restore() is a plain copy. It runs while the climate entity is added, before the memory has seen the two reads it needs to store anything. New test through Home Assistant: the zones of a zone controller learn from the polls, and a mode change of the ducted unit sets them.
|
Thanks both, that's a lot simpler. It's in c960a03 and ad7f5c4, and 92051e2 merges the current
The pending target: Reads and pushes: Storage: it's in Tests: besides yours, there are three new Home Assistant level tests. One checks that a change on the device is learned from the polls, and that entity updates without a read don't count. One checks that the zones of a zone controller learn, and that a mode change of the ducted unit sets them. One checks that the memory survives a reload and a restart. They skip below 2026.11 like yours. With #578 merged on top they all run and pass: 409 passed on HA 2026.11.1. I'll drop the skips once #578 is in. Outside the tests it's 271 lines now, down from 442. Rob, could you give it another run on your unit? The behaviour should match f5abaa9, but the storage, the reads and the option moved. The old |
|
Logic seems much simpler and readable now, thanks for the changes. |
|
Thanks @Twintop, this is much easier to follow. I ran ad7f5c4 again. Tests: with #578 merged on top, 409 passed with no skips, and ruff is clean. My test unit (standalone, Home Assistant 2026.11.1). All changes "outside Home Assistant" were sent straight to the unit, as a remote would:
No errors in the log. I could not test a zone controller, so that part rests on your Home Assistant level test. From my side this is good to go once #578 is in and the skips are dropped. |
A target that was stored in the other unit is converted with TemperatureConverter and UNITS_GREE_TO_HA, as in climate.py and number.py, and then rounded to the steps of the device. Every target in range gives the same result as before, in both directions. 5.0-dev tests on Home Assistant 2026.11 since RobHofmann#578, so the climate tests of the memory no longer skip.
|
@RobHofmann Thanks for the second run, and for getting #578 in. 090d026 merges the current |
Context
This follows #552 (zone controllers) and is the last part of porting the changes I made for my own zone controller (Gree LE60-13/GH) over to this project. It was planned as two PRs, one for the zones and one for every other device. In the review of #552, @p-monteiro asked for one PR for all devices, with the memory as a device option that is on by default, and he suggested the memory for standalone units back in #549. Background and the full plan: https://github.com/Twintop/ha-gree-zone-controller/blob/main/upstream/README.md
Why
The wall panel of a zone controller remembers the target temperature of every zone for each mode, and sets them again when the mode is changed on the panel. A
Modchange over WiFi does not do that: the zones keep the values of the old mode. With #552, a mode change from Home Assistant leaves every zone at the target temperature of the old mode, for example the 18 °C set for Heat now applies in Cool.A standalone or VRF unit has the same gap in a smaller way: one target temperature is shared by every mode, so switching between Heat and Cool from Home Assistant means setting the target again each time.
Change
The memory:
SetpointMemoryinsetpoint_memory.py, next to the coordinator, remembers the target temperature of a device per mode. It uses the typed interfaceGreeDevicealready has,target_temperatureandset_target_temperature(). It does no I/O of its own: the coordinators do the reads and send what it sets.{"<zone mac>": {"heat": {"temperature": 19.5, "unit": "C"}}}. Throughset_target_temperature(), every target in range comes back as the same temperature, with its bit, so a half degree comes back exactly. In °C these are also the same columns. In °F, three values come back with the other encoding of the same °F. A value stored in the other unit is converted withTemperatureConverterand rounded to the steps of the device.GreeCoordinator._update_data()callslearn()after every read, and nothing else does. A device reports its mode and its target temperature in one reply, so the two belong together. A value is only stored when the device reported the same mode on the read before, so a read in the middle of a mode change on the panel or remote is not stored under the wrong mode. Changes made with the remote, on the panel or in the Gree+ app are learned the same way.Powis its damper. A value that was sent and is not confirmed yet is stored once the device reports it.Protocol layer: no changes.
Applying it, only on a mode change made from Home Assistant:
apply()sets the stored target of the new mode without sending it, so it goes out in the same command as the mode. A target given with the mode, asclimate.set_temperaturedoes withhvac_mode, is set by the mode change instead, after that read, and also goes out in the same command. Nothing is recalled into Auto, where the unit ignores the target temperature.apply()sets the stored value of the new mode on each zone, and the zone's coordinator sends it withpush_device_status(), with the IP recovery and the follow-up refresh every command gets. This is what the wall panel does.Home Assistant layer:
setpoint_memory), on the device whose mode changes: a unit with a target temperature, and the ducted unit of a zone controller, where it covers all of its zones, as the wall panel does. It's on by default.manual-configuration.yaml.extra_restore_state_data). For a zone controller that is the climate entity of the ducted unit, since the zones have none and it is the one that sets them. Home Assistant saves it every 15 minutes, on a stop, and when the entity is removed, for example on a reload, and drops it 7 days after the entity is gone. It is restored whether or not Restore Entities is on.en.json,docs/protocol.md,docs/entities.md,docs/configuration.md,docs/config-entry.mdanddocs/architecture.mdare updated.For existing users: since the option is on by default, after updating, a mode change from Home Assistant sets the target temperature that unit last had in the new mode, once it has seen that mode. Until then nothing changes.
Testing
pyteston Linux with Python 3.14 andrequirements_test.txt, as in CI (Home Assistant 2026.11.1): 409 passed, none skipped, on the branch, which includes the current5.0-dev.tests/test_setpoint_memory.pyhas 15 tests against the fake zone controller and a fake standalone unit. They include a zone remembered at 18.5 °C that comes back as 65 °F after the controller was switched to °F, a closed zone that still learns, a unit that is off, and the option being on the ducted unit and not on the zones.tests/config_flow/test_setpoint_memory_climate.pyruns through a real Home Assistant: @RobHofmann'sclimate.set_temperaturetest, a change on the device learned from the polls (entity updates without a read don't count), the zones of a zone controller learned from the polls and set by a mode change of the ducted unit, and the memory kept over a reload and a restart.mypy.ini) and Pylint show nothing new compared to the current5.0-dev.Store, an option per zone), not repeated since:set_temperaturewith a mode keeps the given temperature, and the memory is kept over a restart. With f5abaa9, nothing was learned while the unit was off. VRF units are tested against fakes only.