krahabb / meross_lan

Home Assistant integration for Meross devices
MIT License
452 stars 47 forks source link

Add ability to override internal sensor temperature for thermostat #334

Closed KiraPC closed 9 months ago

KiraPC commented 1 year ago

My thermostat valves (mts100/150) had an integrated temperature sensor that do not display the correct room temperature since them are nearest to the heater.

So I've an external temperature sensor and I would like to use it to override the integrated one.

This functionality is feasible in home assistant getting entity states (do it in my Switchbot integration)

Can you add this option?

krahabb commented 1 year ago

There was another request for this..I'll try to consider the effort needed...we'll see ;)

KiraPC commented 1 year ago

Great.

I'll try to have a look on your code and open a PR if I have time.

lukasz-burak commented 1 year ago

@krahabb I'd really appreciate this feature also for MTS200 Thermostat.

krahabb commented 11 months ago

This feature is now available in pre-release

It is implemented by configuring a source temperature entity ('tracked_sensor' in the configuration page of the device - it might by disabled by default). The source entity might report both °C or °F and they will be converted in case to the °C native temperature of the MTSs When this source sensor publishes an update, meross_lan checks the actual reading of the MTS and 'natively' corrects it by issuing an 'adjust temperature' to the device. This way you should see the corrected/overriden value also in the app since the correction is done by the device itself. The correction is only applied every 5 minutes in order to not start crazy cycles where the sensors keep updating/adjusting and maybe start an oscillation (control theory, that is!) This way, if your source temperature has a 'fast' variation, you could see the tracking not being immediately updated but, of course, this is not usually happening for temperature readings! In the end, when the temperature is stable enough, your thermostat should kindly 'follow' the source sensor.

It was a bit hard to make it work since the MTS100 (I've only tested these devices) do some weird roundings on their setpoints when you set the 'temperature adjust' for the valve. This is because the setpoint (manual, cool, heat or sleep) has a 0.5 °C resolution generally, but when you offset/adjust the temperature reading of the device by less than 0.5° then you start seeing intermediate setpoints. I cannot say what is happening on the Meross app by the way since I've tested the MTS100 binded to a local MQTT broker, but now, in HA, you shouldn't see any 'glitch' in the setpoints when the tracking is in place. This has been thoroughly tested/implemented on the MTS100 while the MTS200, being unable to actually test it, has an unknown behavior at the moment. I expect the overall tracking should work for the MTS200 too but maybe you'll start seeing the setpoints rounding off in strange ways (this is at least what I was experiencing on the MTS100 during initial development: I've then refined the code for the MTS100)

I'm eager to see your results and keep refining this very nice feature. I think it will have a lot of interest (and useful cases)

KiraPC commented 11 months ago

Hi @krahabb

Thank you a lot for your work.

I'll try it asap and let you know if some issues appear.

EDIT: Installed, it's working.

lukasz-burak commented 11 months ago

@krahabb man, appreciate that a lot! Currently testing on few of mine MTS200 and so far seems to work just fine, will update once it will work for few hours/days to see if there are no issues with it.

This solves my biggest issue with MTS200 which is that this device heats up a bit during work and that affects its internal sensor accuracy.

I’m actually having helper sensors in HA that track difference between external sensor and internal sensor and was doin such calibration by hand to fine tune it, very happy now it will be automated!

EDIT: so far all seems to work just fine, enabled on all my thermostats without any issues so far.

giabett commented 11 months ago

I also use this feature, that is great, as in my rooms there is quote e big difference between real temperature and the one at the valve. It seems it works, even if I notice that also the target temperature sometimes change of 0.1°. So if set at 20° sometimes it shows 19.9 or 20.1. Also the graph is storing this changes, see:

image

as you see I changed Dec 8th at 21, before that the set temperature was a constant line (pink) after it is little bit changing of 0.1°

giabett commented 11 months ago

it also mess up the preset temperature:

image

away temperature is normally set at 15, now I found all 5.2 same the sleep temp is 15 and now 5.2

krahabb commented 11 months ago

@giabett, It might be the MTS150 are behaving differently than the MTS100 with the setpoint roundings. the MTS100 has a 'somewhat failing' rounding mechanism so I've patched the valve readings in order to show correctly rounded values in HA (at least in my tests) This 'patching' might be wrong for the MTS150 so, if the issue arise only on those, we could adjust the code for the case. I'd need a trace for one of those in order to see what's reported by the valve when the offset/target tracking are in place. When tracing, disable the sensor tracking first, and try to manually set the 'adjust' temperature to different values like: 0.1 - 0.2 - 0.3 - 0.4 - 0.5. Whenever you set a new 'adjust' also change the setpoint (like increasing or decreasing it by some degrees) and then wait like 30 seconds before stepping up the adjust again

giabett commented 11 months ago

msh300hk-1702208887.csv hope tracing is ok, thanks

KiraPC commented 11 months ago

@krahabb I'm testing the feature and seems that after restart or after a while the server is running, meross integration lost the list of available sensor.

So even if I configured the temp sensor it desappear and it is se to off

krahabb commented 11 months ago

@krahabb I'm testing the feature and seems that after restart or after a while the server is running, meross integration lost the list of available sensor.

So even if I configured the temp sensor it desappear and it is se to off

@KiraPC , thank you for signaling. I think the issue lies in the fact that, depending on the HA boot sequence, some entities are registered before and some other later than meross_lan so that, when it starts, not all previously available entities are (still) there. meross_lan builds this list just while initializing so it is easily bugged. I guess the fix is 'very' needed ;)

KiraPC commented 11 months ago

@krahabb yes I supposed it.

I see anyway, that the difference cannot be greater then 5 degree

krahabb commented 11 months ago

@KiraPC , yes, that's the limit of the valve 'adjust' feature. In order to overcome that limit I would need to implement the whole thermostat logic in meross_lan but then, it would be easier to just use a kind of 'template thermostat' (if that exists in HA I'm not sure) or an automation. I'll think a bit about that but, at first sight, a total override of the valve would be 'too much' in my opinion

KiraPC commented 11 months ago

Unfortunately there is no a 'template thermostat', just a "generic climate" but it need a switch entity and some else.

giabett commented 11 months ago

also after this new update external sensor seems not working in the right way. See the graph after using remote sensor instead of the internal one:

image

The temperature of the external sensor was always stable, only little changes of 0.5°

image

krahabb commented 11 months ago

mmmh..I can't figure out what is happening. It looks the climate reading goes up to 26 °C with those fast fluctuations..hard to think they're a consequence of the T adjustment since the MTS can only be adjusted by 5 degrees max (I guess the MTS150 have this limit too. It would nice to have a debug log active for a long period of time....I'll think a bit more about that

giabett commented 11 months ago

Analyzing it more closely, probably the issue started when the difference between the external and internal sensor temperatures exceeded 5°C. For a few days now, I've been using the external sensor on both valves, and everything seems to be working fine.

krahabb commented 10 months ago

Similar to #95