Hey community,
I want to control a heating element through a PWM to voltage converter (0 to 10V). The electronics part is working but I’m struggling with the integration in Home Assistant.
How do I now properly link this to Home Assistant? I would like
the current level from the ESP as an entity value
the ability to change the value (e.g. through Home Assistant automation)
Maybe I’m missing something obvious here… I could hack a light entity to do the job but that can’t be it. There has to be a cleaner way. Grateful for any hints!
Thanks!
Btw. For testing purposes I added this quick proof of concept:
switch:
- platform: gpio
name: "test"
pin: D2 # there is actually nothing connected here
on_turn_on:
then:
- output.set_level:
id: pwm_output
level: 50%
This works and produces the expected 5V out upon switching from HA.
I would probably start by using a Template Switch instead of the GPIO platform if you want to do control from HA rather than locally on the ESP. Actually two template switches maybe - one to turn up frequency and one to lower it?
As for outputting to HA the current value, again templates, the Template Sensor.
Do all the range checking for low and high values in the template switches. Store the current value of the output in a Global Variable.
Have a read of Automations and Templates - it’s full of lots of good stuff.
It is ridiculously complicated for such a simple task - but it does the trick.
Now here is the issue. Buttons to increase or decrease by 10% won’t cut it In order to control the heating system I need to send an absolute value (e.g. 55%) from a Home Assistant automation. I don’t see the ESPHome integration providing an HA service. I also thought about the ESPHome REST API but it doesn’t seem to allow writing directly to a global variable.
This little project is my first contact with ESPHome and so far it does not compete well But I’m here to learn. Any further help would be hugely appreciated
There is a home assistant sensor! I didn’t expect that.
Strange circular dependency and cognitive overhead this adds to the control system What do you think? Do you by any chance know whether a HA service to send a command to ESPHome is planned?
It is now fully working. Leaving the solution for others.
I left the ±10% switches from above and the global variable in for now. If I decided to remove them at a later point, the logic could be a simplified. After all I am very happy with the result.
Thanks @zoogara! Please leave another comment so I can mark it as the solution.
Glad it’s working ok. ESPHome sort of already gets commands from HA, in the form of MQTT or API messages to perform switching etc. There is a component in ESPHome to go the other way - i.e. directly perform HA service calls from ESPHome, but nothing to do things like pass values or commands to ESPHome other than the things you are already using.
You can already do that. You can define a service in your ESPHome yaml that you can that call as service in HA automations. See: Native API Component — ESPHome
I have to be honest, I totally underestimated how tightly integrated ESPHome is with Home Assistant. I didn’t even think about the possibility that you might be able to access HA entities, let alone, expose a service to it.
Good point and I would have accepted that. However thinking about it: The application will be static (no regular reboots) and when it does I’d rather have a safe state to recover via HA from. I’ve removed the option.
@mupsje you need to find your own configuration that serves your needs. Mine includes other sensors and settings. Hence the following is not the complete yaml and beware that I have changed a few things.
Additionally, In Home Assistant I’ve defined a couple of input_number entities to get from my wanted set temperature to voltage to PWM level. In testing that looks like this:
i think i have the same plan as you already solved
I have a lot of temperature sensors on my heating system. One of my pumps has an integrated heat meter function, but requires an analog input 0-10V from the return.
I have already integrated some DS18B20 and read them out via an ESP32. Now I am looking for a solution how I can generate a 0-10v output sensor via the ESP.
I still don’t understand in your solution how you generate the percentage output from another temperature sensor in Hassio and return it to the ESP? If I overwrite the 30% in hassio, will it be set back to 30% after 60 seconds and not the value in the ESP changed? What am i forgetting?
Hey!
Above I only showed the code for ESPHome. This device exposes a service (through the code in the api section), which can be called by a Home Assistant automation. The sliders that I showed in the screenshot have this automation behind:
automation:
- id: "1618577571740"
alias: Regel Heizungsregelung Sollwert über Prozent Schieberegler
trigger:
- platform: state
entity_id: input_number.heizungsregelung_sollwert_prozent
action:
- service: esphome.heizungsregelung_eigenbau_set_heiz_sollwert_percent_pwm
data:
percentage: "{{ trigger.to_state.state | int }}"
I know it’s been a while, but I hope I can ping you still. I’d like to solve a very similar issue: control my Wolf CWL400 ventillation system with 0-10V input based on various existing HA sensors data (presence, humidity, temperature, etc).
Would you be willing to share with me/us your complete config - both ESP yaml, and HA automation setup - and your electronic setup as well (what devices did you use as ESP and as PWM), so I can have it as a guide to build my own setup?
What I’d like to achieve:
be able to read from ESP what is the current level of ventillation
be able to instruct my ESP to set PWM to certain level based on HA sensor changes (eg. humidity drops below certain value, then drop ventillantion to X%, overrule this based on time of day, eg- have a constant low PWM during the night, and completely shut down ventillation when outside air quality sensor reports bad aur quality near air intake to avoid spreading bad smells in the house).
Hey! Sorry I didn’t answer. Reason being, that we postponed the implementation of this new heating control. I wanted to get it finished for this winter but we decided to hold off and install, test and take online for the winter to come.
Everything I can provide to learn from is posted above. Hope it helped
Could you tell me what kind of hardware you’re using? I plan on doing something similar as you, I want to control my heat pump via a 0-10V Input when I have excess power from my solar panels.