Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESPHome support #8

Open
rdehuyss opened this issue Nov 3, 2022 · 24 comments
Open

ESPHome support #8

rdehuyss opened this issue Nov 3, 2022 · 24 comments

Comments

@rdehuyss
Copy link

rdehuyss commented Nov 3, 2022

Hi, are you considering support for an ESPHome module?

This would increase your potential market by a lot...

Thanks!

@Jeroen88
Copy link
Owner

Jeroen88 commented Nov 4, 2022

Hi Ronald, I would surely consider supporting ESPHome, I already took a quick first glance and it looks indeed very interesting. Do I understand correctly that you need Home Assistant? And that MQTT is the protocol used to communicate between HA and the devices?
I already published a first draft example of a MQTT thermostat in the examples? What would you suggest that is needed to support ESPHome?

I think it would be nice also if the MQTT thermostat could listen to a (external) temperature device!

@bwired-nl
Copy link

EasyOpentherm supports mqtt, which can be used by all Home automation software for example also Home Assistant and Domoticz

@Jeroen88
Copy link
Owner

Jeroen88 commented Nov 6, 2022

So the MQTT example in this library supports your needs?

I am working on a next version of the MQTT example, a different loop() and adaptations to the logic how to decide to turn the boiler on and off. As soon as this is ready I will make a new release. So keep an eye on the changes. Also I am considering ESPHome native API support after updating the MQTT example.

@Jeroen88
Copy link
Owner

Jeroen88 commented Nov 20, 2022

I am still working on this. The new (yet to be published) thermostat implements a state machine: from WAITING_FOR_BOILER (no valid response received yet from the boiler) to OFF (boiler connected but thermostat in off state and does not react to changes in room temperature) to IDLE (thermostat reacts to changes in room temperature but the current temperature is within range of the room temperature set point) to either HEATING or COOLING (boiler is running) to ANTI_HUNTING (after a running cycle, boiler will not start running again for 5 minutes) to IDLE again. In any of the previous states but the first it can go to OFF if it receives a command to do so. From OFF it goes to any of the running states only by changing the set point. The state is selected depending on the difference between room temperature and room temperature set point. This new thermostat also implements a dead zone (i.e. temperature needs to drop below set point minus dead zone before heating starts up).

In this new thermostat the WiFiClientSecure is changed into a WiFiClient, the certificate is removed and the HiveMQ external broker is replaced by the Mosquitto broker, because running Mosquitto over a "normal" (non TLS) connection is a more logical scenario from a home assistant point of view. In this way it will seamlessly work with the MQTT integration present in home assistant.

I am also investigating MQTT auto discovery, ideally I want the MQTT thermostat be discovered automatically by the MQTT integration as a HVAC integration that can be controlled by a thermostat card if this is possible.

I will publish this new MQTT thermostat within weeks.

Also I have developed new hardware: an OpenTherm shield especially designed for an esp32 S2 mini that I expect to work also with an ESP32 C3 mini or even the older ESP8266 D1 mini. This will be available within 2 weeks I think.

@Jeroen88
Copy link
Owner

Jeroen88 commented Dec 5, 2022

@ananyevgv thank you for all the links! :). Currently I am working on the MQTT integration of the EasyOpenTherm library for Home Assistant. The links you provided help me to create a native API version afterwards.
The difference between the solutions of the links that you provided with the solution I am developing are: I am focussing on offering a high level API, basically setting the room temperature setpoint and providing or measuring the current room temperature only, and the controlling of the boiler being taken care of by the library. My solution is not a gateway but a replacement for the wall thermostat, communicating with HA not by serial but using MQTT messages (and the HA native API later on). I did not investigate the fourth link due to lack of structure of that repository. I just quickly read about the Daikin solution, which seems to me an integration of an existing hardware component with HA, so a very different approach than EasyOpenTherm.

My short term goals are:

  • Offering a high level API to a fully automated thermostat controlling the boiler
  • Auto discovery of a Climate entity in Home Assistant
  • Auto discovery of several sensors and binary_sensors (currently boiler setpoint, boiler flow temperature, boiler return temperature, WiFi signal, flame ON/OF, hot water for CH/DHW. These sensors are easily extendable
  • Offering generic hardware for any microcontroller and dedicated hardware for an ESP32-S2 mini, ESP32-C3 mini that most likely will also work with the ESP D1 mini.

Ultimately this will lead to: setting up the MQTT integration in Home Assistant if not already done, set your WiFi and MQTT credentials, compile and flash the microcontroller, connect it to the two OpenTherm thermostat wires to the boiler and you are ready to go. Should be ready before the end of this year :).

@ananyevgv
Copy link

Hi friend. It would be very nice. I tried many implementations, but unfortunately I didn't get what I wanted. I'm ready to test your version. I can throw off a few more links., with the implementation of mqtt.

@ananyevgv
Copy link

@Jeroen88
Copy link
Owner

Jeroen88 commented Dec 5, 2022

Hi friend. It would be very nice. I tried many implementations, but unfortunately I didn't get what I wanted. I'm ready to test your version. I can throw off a few more links., with the implementation of mqtt.

Keep an eye on this repository, when the Home Assistant MQTT auto discovery example is ready I will issue a new release.

@Jeroen88
Copy link
Owner

A small update for if you are interested :)

  • New hardware shield is functioning correctly, I will put it in my Tindie store at the same time I update the library on Github
  • MQTT auto discovery took a lot more time, because the documentation is not very clear. Also fully functional now, although I think I have to spend some time on retention of the right messages
  • A Climate entity is auto-"magically" added with "off" and "heat" button if the boiler is heat-only, and extra "auto" and "cool" buttons if the boiler can cool
  • The thermostat not only can use a local temperature sensor but also listen to an external thermometer already present in Home Assistant. For this I wrote an automation Yaml that picks up the thermometer value and forwards it to the right MQTT topic in the right JSON format
  • A Domestic Hot Water (DHW) switch is added, if the boiler supports DHW. When switched off the boiler will not produce domestic hot water
  • The following sensors are always present: flame (on/off depending on if the boiler is burning), RSSI (WiFi signal strength), boiler setpoint (target temperature for the boiler),
  • The following sensors are only added if the boiler supports these: water pressure, flow temperature, return temperature, relative modulation, domestic hot water (if 'on' and flame is also 'on' the boiler is running for DHW, if 'off' and flame is 'on' boiler is running for central heating)

Still a lot of code cleaning to do, updating the state machine, adding comments in the code and adding a description for MQTT example. So give me another few weeks.

@Jeroen88
Copy link
Owner

@rdehuyss, @bwired-nl, @ananyevgv I just pushed a new release v1.1.0. Apart from a few minor changes, the Advanced_Thermostat.ino example now is a Home Assistant fully functional auto discovered MQTT Climate HVAC Thermostat:

  • Set your WiFi and MQTT credentials in Advanced_Thermostat.ino
  • Check the OT_RX_PIN and OT_TX_PIN GPIO's used to communicate with the OpenTherm controller if you do not use the shield (The GPIO pins have been changed since the previous release to match the shield)
  • Flash to an ESP32-S2 mini or an ESP32-C3 mini. These boards have been tested. It will definitely work on other ESP32's too, for an ESP8266 some code changes are needed but could work too.
  • VERY IMPORTANT: add an automation in Home Assistant that forwards the room temperature from an existing thermometer in Home Assistant to the right topic (see README.md for instructions on how to do this.
  • Connect the two OpenTherm thermostat wires to board or shield.
  • Power the ESP32. The MQTT HVAC Climate control should be auto discovered on the Home Assistant dashboard. If no temperature is shown just above the middle of the thermostat, the publishing of the room temperature is not correct yet. If the EasyOpenTherm board or shield is not communicating with an OpenTherm boiler (e.g. because the wires are not connected yet) the HVAC Climate entity will appear in Home Assistant but disabled.
    If you already see the entity appear you are on the right way!

The MQTT Integration and a MQTT broker (like Mosquitto) should already be installed without TLS / Certificate and reachable on port 1883.

Please report back your experiences!

@ananyevgv
Copy link

Compiled it, I'll try it in the evening. Will DS18B20 work too? It would be nice to add an MQ5 (or similar) and a relay to control the gas valve.

@Jeroen88
Copy link
Owner

@ananyevgv if you set the const int oneWireBus here to the GPIO where your DS18B20 is connected, the program will publish the room temperature measured by the Dallas sensor to Metriot/EasyOpenTherm/112233445566/climate/state in the format {"local_temperature":19.8} (you have to replace 112233445566 with your unique chip ID). If you want to use that temperature you have to send it back by publishing it to the same topic in the format {"temperature":19.8} using a Home Assistant automation.

So the decision which thermometer you use to inform the thermostat of the room temperature is made in Home Assistant (or any other home automation system: the thermostat subscribes to .../climate/state topic and uses the temperature it gets with the right JSON key "temperature").

@Jeroen88
Copy link
Owner

@ananyevgv the MQ5 is a gas sensor, not a thermometer, so not usable for the purpose of measuring a room temperature. I used a I2C BE280 in the MQTT_Advanced_Thermostat.ino example, please take a look there if you need an example of how to read another temperature sensor. Next adapt the program to integrate those readings instead of the Dallas.

But the best option is to use a thermometer completely independent of the thermostat and publish the value to the above topic in the right JSON format.

For other home automation systems based on MQTT I would also suggest to use the new Advanced_Thermostat.ino example, because this is also based on MQTT and far more complete than the older MQTT_Advanced_Thermostat.ino example. With the new example just do not subscribe to the Home Assistant auto discovery messages.

@leovanalphen
Copy link

leovanalphen commented Jan 3, 2023

Question, can this work together with zigbee smart radiator valves/buttons? I currently have a Nest thermostat, Nefit opentherm CV and dumb radiator valves. But I don't like the nest and I would like to be able to heat and control heating for separate rooms. (I work from home, so most of the time i'm sitting in my small office, no need to heat the livingroom for example) + I'm really interested in getting more insight what my boiler is doing. I've also looked at Tado and Evohome but these are cloud based, I would really prefer something local for multiple reasons.

Can I use either your OpenTherm shield or OpenTherm controller to heat rooms independently with zigbee radiator valves via Home Assistant? I already have temperature sensors in every room + what I can see most of the smart valves also have a temp sensor.

Would something like this work? Thanks in advance!

@Jeroen88
Copy link
Owner

Jeroen88 commented Jan 3, 2023

Hi Leo, yes I definitely think this can work! I am thinking of such a setup myself. A few thoughts:

  • Zigbee or any other physical communication layer is not important (in the sense that it has nothing to do with the thermostat)
  • You should look for valves that you can control independently from the temperature that is measured by the valve itslef
  • Basic information you can get from your boiler depends on your boiler. My Remeha responds to flow and return temperature but not to water pressure, so these are boiler dependent. Also Domestic Hot Water / Central Heating and relative modulation if supported. You always get the flame on / off, WiFi signal If you want to read out other sensors that your boiler exposes to the OpenTherm interface, those can be easily added to the software.
  • This thermostat does not share any information in the cloud indeed (unless you share it yourself or use a public MQTT broker)

Yes you need just one shield to replace the room thermostat. You can place it near your boiler if you want to, as long as you have a good WiFi signal. You should come up with some kind of strategy what temperature you send to the thermostat, using a Home Assistant Automation. I would think of something like the temperature with the highest delta T. This is needed to turn the boiler on and off. You should manually add Climate entities to Home Assistant for each room to be able to get setpoints. And you should either have the valves regulate each room temperature OR do this yourself from Home Assistant (hence the advice to have independently controllable valves).

Please share your thoughts and results here or in the discussion section

@leovanalphen
Copy link

Thanks for the fast and indepth response!

The way I was picturing it in my head is exactly as you say, install the shield next / close to the boiler. Then have the valves talk to home assistant, and home assistant talk to the thermostat / shield.

You should look for valves that you can control independently from the temperature that is measured by the valve itslef

I was thinking it would be enough to be able to set and read the temperature of the valves. Then make an entity in HA that groups all the valves, filter out the ones which are below the set temp for that valve and then pick the highest temp out of the bunch to send to the thermostat. I was thinking the valve at the radiator will then automatically shut off when the set temperature is reached (closing the valve), since its now at or above the set temp, it would be filtered out of the group of valves and HA again picks the highest temp to sent to the thermostat, until the group is empty and the thermostat can go to idle/off.

Hadn't really considered being able to independently control the valve position from the set temperature of the valve, I thought just setting the set temperature of the valve via HA would be enough. I'll see if I can find valves that support this, do you have any suggestions? I was looking at valves like this or this, but these might not be the right fit then. Having the option of controlling the valve position independently from the set temp on the valve does give a lot of flexibility.

Basic information you can get from your boiler depends on your boiler. My Remeha responds to flow and return temperature but not to water pressure, so these are boiler dependent. Also Domestic Hot Water / Central Heating and relative modulation if supported. You always get the flame on / off, WiFi signal If you want to read out other sensors that your boiler exposes to the OpenTherm interface, those can be easily added to the software.

I saw you added a script that read out which things my boiler can return, I understand it differs per manufacturer and model. I see any info / insight in operation as a welcome bonus, but my main goal is being able to heat rooms separately, getting smart control of my heating and not having to deal with cloud. Getting extra info from the boiler for possible gas savings / boiler tuning (and because it's interesting and fun!) and having a fun project to tinker on is a nice extra :)

@Jeroen88
Copy link
Owner

Jeroen88 commented Jan 3, 2023

Hi Leo, sure, I like your interest!

One other thought: you should probably exchange the valves in your living room. Most central heating systems have ordinary valves in the living room because that is where the thermostat is Changing those valves involves replacing the complete valve, not only the knob, so you have to drain the heating system. This is because the living is no more the "reference room", just an ordinary room like all others. Still I think you can start without exchanging them but then your living room temperature will be dependent on the decisions made for the other rooms.

I have no experience with smart valves so I can't give you any advice. I was browsing Ali and I like these (without really reading the specs). I do not like to set up Zigbee, I'd rather have WiFi, but most of these valves have Zigbee.

Yes with the script you can find out what DATA-IDs your boiler responds to. Adding extra sensors is quite simple: add a JSON in JSONs.h and add it on two or three places in the program like the existing sensors. Indeed a bonus :)

@leovanalphen
Copy link

leovanalphen commented Jan 4, 2023

Yes, sadly I will have to replace all the valves/ventielen, my house is old and sadly all the radiators still have old school (manual) valves without thermostat function, so I figured since I have to empty the CV system anyway I might as well immediatly replace all of them with thermostat valves, and for now only add smart to one or two rooms to test and see how it goes. Also a good time to add radiator foil and radiator fans while I'm at it :)

I've been looking for a nice smart valve but from what I can see they all have downsides, some don't even report their battery level, others you can read the set temp but not actually set the set temp, others don't allow use of an external temp sensor to calibrate the thermostat in the valve (I read pretty much all of them report incorrect temp because it's so close to the radiator, I thought manufactures would have this calibrated but from what I can see pretty much none do.), Others do not report their valve position (haven't found any so far that allows to directly set valve position irregardless of the set temp).

It seems there are 3 or 4 manufactures of valves, and then about 20 'white label' resellers like Aqara, Moes, Silvercrest, etc. Dumb thing is that some of the whitelabel stuff has smart functionality disabled that the OEM version DOES have enabled and vice-versa, so it seems it is a bit of a minefield.

So far I'm leaning towards Tuya TRV-02 valves (the same ones you linked above), read some good things about them when it comes to direct smart control, but it seems there are also countless versions of the TRV-02 all with their own quirks and things they do or do not support, and finding this info on store pages is so far not easy.

I'm going to keep looking for a good smart valve for a bit, and in the mean time get the thermostatic valves and radiator foil fitted. I'll let you know when I've made a choice :)

@Jeroen88
Copy link
Owner

Jeroen88 commented Jan 8, 2023

Hi @leovanalphen, any progress on your quest for smart valves?

I read pretty much all of them report incorrect temp because it's so close to the radiator, I thought manufactures would have this calibrated but from what I can see pretty much none do.)

I agree, the best thing those valves can do is substract a few degrees, but this will never be accurate. I use a lot of those dirt cheap Xiaomi Mijia Bluetooth Thermometer, reflashed with other firmware using Telink flassher and next set the beacon to BTHome. Wireless, battery operated thermometer and hygrometer with battery status updates everywhere you want it!

@leovanalphen
Copy link

Hi @Jeroen88, not yet! I've ordered the required thermostatic valves/ventielen. Should be here somewhere around Thursday. Then I have to find a moment to drain my CV system and fit them before I can mount any smart valves to the radiator.

Funny, I have the same Xiaomi sensors in every room 👍 Which is also the external temp I wanted to use. Haven't flashed them with different firmware though, I have them hooked up to Hass.io via the BLE monitor integration and so far they work great!

I'll keep you posted!

@Jeroen88
Copy link
Owner

Hi @leovanalphen what valves did you decide to buy?

Funny, I have the same Xiaomi sensors in every room +1 Which is also the external temp I wanted to use. Haven't flashed them with different firmware though, I have them hooked up to Hass.io via the BLE monitor integration and so far they work great!

Nice!

@craigsbits
Copy link

craigsbits commented Mar 3, 2023

For Home Assistant I flashed them with the Telink flasher. So easy. Then use an esp32 flashed as a ble wifi repeater in esphome to guarantee a good (wifi) connection to HA. I use SONOFF Universal Zigbee 3.0 USB Dongle plugged into HA (NUC) for the radiator TRVs and use the internal sensors as i found them to be quite good (my TRVs are at the top of the radiator, on water supply, and stick out sideways. So don't pick up local heat). Cannot directly control them from another sensor! Tuya clone "TS0601_thermostat_1" but can use the calibrate to do 'pseudo' control! One problem I did have with TRVs is the Schedule function which I never used but these little "*****" must have an internal clock if that gets away from reality it needs to connect to the tuya gateway mothership to get the correct time or it starts messing about. Now where did I put it!! -bin? Mine spoke in Chinese very annoying.

@craigsbits
Copy link

Zigbee2mqtt.io is a good resource for info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants