kotope / valloxesp

Vallox Digit wifi controller with Home Assistant integration through MQTT
MIT License
22 stars 9 forks source link

ESPHome and native API #12

Open MarkoPaasila opened 2 years ago

MarkoPaasila commented 2 years ago

This is actually two questions: Should this work with esphome? What would it require to use valloxesp with the esphome/home-assistant native api?

kotope commented 2 years ago

Hi,

MarkoPaasila commented 2 years ago

It looks to me, according to this guide, like you can use any cpp/arduino code with esphome - the point being that people don't need to rewrite code written for other frameworks. I don't mean to push you - only make sure you are aware of this.

I accept the answer - of course. I had a look at your code and it looks really nice. Awesome work. Thank you for this project. I have ordered the components and intend to test it soon.

EDIT: Here's one example of a functioning arduino component integrated with (or wrapped into?) esphome.

kotope commented 2 years ago

Thanks for the info, after all ESPHome might be suitable for this also. Most probably would need to rewrite the .ino part of the code, but that should not be too big of a deal.

However, more work might need to be done to get rid of the custom_component along with that. I might have a look at this at some point, if I have time, but can't promise anything :-)

github-k8n commented 2 years ago

Actually I am currently trying to write a custom climate component in ESPhome by mostly copy/pasting your code. So far after half a day I have the code working and it's updating a custom sensor with the fan speed (for testing basic functionality..).

However during that I noticed that the lastRetryLoop variable within void Vallox::loop() is never updated? I might be missing something but it looks like it stays 0 and thus the condition (now - lastRetryLoop > RETRY_INTERVAL) is true each time thus running the retryLoop() each time.

github-k8n commented 2 years ago

Ok, here's a cobbled together version that might need some improvement. However it's working fine for me now. How to install:

Vallox_esphome.zip

kotope commented 2 years ago

Actually I am currently trying to write a custom climate component in ESPhome by mostly copy/pasting your code. So far after half a day I have the code working and it's updating a custom sensor with the fan speed (for testing basic functionality..).

However during that I noticed that the lastRetryLoop variable within void Vallox::loop() is never updated? I might be missing something but it looks like it stays 0 and thus the condition (now - lastRetryLoop > RETRY_INTERVAL) is true each time thus running the retryLoop() each time.

lastRetryLoop is being used on mode setters only. It is set as current time and will be cleared right once we got reply for our request. This ensures that the setters are always working even in case of transport failure. Of course there can be bugs, need to debug a bit to see if there's something odd in there once I get back from vacation.

And thanks for making ESPHome version! I'm sure some will make big use of that :-) You can of course fork my repository and keep maintaining the ESPHome version yourself if you like to.

MarkoPaasila commented 2 years ago

Ok, here's a cobbled together version that might need some improvement. However it's working fine for me now. How to install:

* Drop Vallox.h into the esphome folder.

* copy content of Vallox.yaml into your esphome config for your device (you might want to adjust the pins for the UART (serial connection), i'm currently testing/using a different esp8266 board (nodemcuv2)

Vallox_esphome.zip

I'm using this now. As far as I can test it seems to work perfectly.

github-k8n commented 2 years ago

@kotope , considering that your blog might come up as one of the top hits when looking for a solution to control a vallox unit, it might be great if you could somehow also include it in your repo.. (also, I'm lazy :D) If there is any question about the license (it's mostly your code anyways....), any changes done by me are public domain.

kotope commented 2 years ago

@kotope , considering that your blog might come up as one of the top hits when looking for a solution to control a vallox unit, it might be great if you could somehow also include it in your repo.. (also, I'm lazy :D) If there is any question about the license (it's mostly your code anyways....), any changes done by me are public domain.

Right, I will add your ESPHome implementation to the repository and add a small text to the blog, once I get back home from a small vacation trip. I will also mention your github name as contributor.

MarkoPaasila commented 2 years ago

@github-k8n I just want to say thank you.

github-k8n commented 2 years ago

@kotope There are a few things still to fix, like a debug statements that were left in, proper formatting and some small issue where home assistant is showing it being turned on again after a few minutes when it was turned off via automation.. so if you can include that in the repo i can then send pull requests later for it (don't have that much time at the moment to completely fix it now ..)

github-k8n commented 2 years ago

One small note on usage i forgot to mention: When using an ESP-01 make sure you do NOT include the "logger:" component. (otherwise it will log debug output to the serial connection which is the same as the RS485 connection used there and cause the connection to fail and there seems to be no way of telling esphome to only log via API) Thus, when debugging use some other ESP board with separate GPIOs.

MarkoPaasila commented 2 years ago

According to esphome docs you can use UART0_SWAP.

kotope commented 2 years ago

Just created a branch for ESPHome implementation (https://github.com/kotope/valloxesp/tree/esphome)

github-k8n commented 2 years ago

ok, so now it should be hopefully be cleaned up, included the UART0_SWAP option, the off mode works fine, speed sensor is now also reporting 0 when ventilation is off .. https://github.com/kotope/valloxesp/pull/18

@MarkoPaasila as you might be at the moment the only other person using that code, let me know if you notice any issues or problems :)

MarkoPaasila commented 2 years ago

I'm currently running the uponor branch because of my older machine, but I'll try this out soon.

MarkoPaasila commented 2 years ago

Ok tested. I included the changes from the uponor branch and it all works. When hvac_mode is turned off, the fans really turn off, speed is reported as 0, and only the control panel displays the previous speed. That is obviously out of scope for this project. Turning the fans back on also works.

MarkoPaasila commented 2 years ago

Can I somehow get the logger output to show raw hex values from communication both ways?

MarkoPaasila commented 2 years ago

One thing that seems missing is reading the RH value.

github-k8n commented 2 years ago

Tried to add the RH values in https://github.com/kotope/valloxesp/pull/19

However I can't test as I don't have the sensors installed.

Will check later to see how if logging could be added if needed

MarkoPaasila commented 2 years ago

First test no results. I'll have to check my files as I have combined lines from esphome and uponor branches... I'll be back.

MarkoPaasila commented 2 years ago

It doesn't return the RH.

sleepymaxx commented 11 months ago

Hi together, sorry to be a little late.. but im making my way through. i have already installed a ESP8266 D1 Mini nearby my Vallox for measuring my Water Flow - so my idea was to add the readings and the sensors to my "old" ESP so i purchased only the RS485 to TTL, made all the installations and the power suply trough the ESP8266 hardware ready to go! Afterwards i wanted to go furthermore: i followed your hints:

* Drop Vallox.h into the esphome folder.

what im missing ---- there is no going furthermore. Sorry for bad english... its a little bit rusty... :-)

github-k8n commented 11 months ago

You did add the Vallox.h file from here into your esphome directory? https://github.com/kotope/valloxesp/tree/esphome/esphome

Can you paste your esphome config? Can you paste the full log/error you are getting when trying to compile in esphome?

sleepymaxx commented 11 months ago

wow. nearly too fast: i updated my vallox.h with your new one... connected sucessfully.... thank you very much!!! settings

`"Code"esphome: name: "wasseruhr-esp" friendly_name: Wasseruhr

Vallox

includes:

esp8266: board: esp01_1m

Enable logging

logger:

Vallox

baud_rate: 0

Enable Home Assistant API

api: encryption: key: "xxx"

ota:

wifi: ssid: !secret wifi_ssid password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap: ssid: "xxx" password: "xxx"

Vallox

uart: id: uart_bus tx_pin: GPIO4 rx_pin: GPIO3 baud_rate: 9600

Vallox

captive_portal: globals:

Vallox

sensor:

Vallox

temperature sensors

no furthermore errors while installing! will report as soon as i got time from my wife! Thanks very much!

sleepymaxx commented 11 months ago

Seems like i installed the wrong Vallox.h file!

github-k8n commented 11 months ago

Happy to hear that it is working.

(When pasting code maybe use the "Code" feature above the text box, otherwise it becomes unreadable... :)

Small note, I heard about home assistant discontinuing the possibility to mark a sensor as "unavailable" by sending NaN as the value. Thus, if you don't have humidity sensors installed it could be that they might need to be commented out in the future (multiple lines in Vallox.h and Vallox.yaml) ... if anyone ever experiences issues around that let me know. (I don't have humidity sensors so I can't really test there..)

sleepymaxx commented 11 months ago

i tried to put it in with "Code" < > (by editing) but somehow i think the outgoing Format from my ESPHome integration in HomeAssistant wont give out the correct coding.

Somehow im getting furthermore errors - i tried to change the RX/TX Pins - Then i got more infos in my Dashboard but at least there are more than only a few without the right readings / writings

grafik

so i shot the first log of my esp: logs_wasseruhr-esp_logs.txt the second log is with changed RX/TX Pins - less correct readings and also missing entrys so to get rid of the [21:26:11][W][component:214]: Component <unknown> took a long time for an operation (0.80 s). [21:26:11][W][component:215]: Components should block for at most 20-30ms. i rewrote the whole yaml file and added on nearly every sensor a " update_interval: 60s" argument... but also here no better readings... and the errors aren´t gone.

(by the way i have already installed 1 Rh (humidity) sensor.

I tested also to give my ORINALLY installed Controller (FDB 382) a other Bus Adress (i changed it to 2) because so you wont get a bus error... but also no positive changings...

Question here: is it nececary that ther are both RS485 to TTL LED´s are blinking? they only blink vise versa when im changing RX/TX?

Thanks in advance for your help!

github-k8n commented 11 months ago

You can try debugging UART https://esphome.io/components/uart.html#debugging ... to see if you actually get any data when you do something like changing the speed (via the "normal" (hardware) control panel, i.e. not vial HA/ESP).

I would also recommend to use a separate esp for vallox to see if everything works as expected. after that you can try to add a pulsemeter sensor or whatever you want to add there... (especially if you still have hardware issues?)

Finally I am currently in the process of completely redoing this integration as an external module (way easier to integrate that way) , but probably will not help in your case (the old integration is working fine for me..)

github-k8n commented 11 months ago

Ok, here is the new version. Just create a folder "external_components" in your esphome directory and extract the file there.. alternatively you can include external components directly from github. @kotope , ideally if you just replace everything in the esphome branch with the content, then it can be pointed to directly according to https://esphome.io/components/external_components.html

Example yaml is included in the archive file

vallox_external_component.tar.gz

kotope commented 11 months ago

Thank you @github-k8n for the ESPHome support and helping people with this issue! 👍

I agree that it would be ideal for the ESPHome branch to contain only the ESPHome support.

Would you mind sending a pull request of this external component support for the ESPHome branch? As discussed earlier I'm currently only using the MQTT way and custom_component so I can't really test if before pushing to the branch :-)

github-k8n commented 11 months ago

Created https://github.com/kotope/valloxesp/pull/33 ... i think it still contained some previous small changes as i didn't sync the branch correctly before, but that should become irrelevant as those files were deleted anyways.. (i don't use git very often ...)

github-k8n commented 11 months ago

Ok, next attempt... https://github.com/kotope/valloxesp/pull/34

github-k8n commented 11 months ago

@sleepymaxx , you can give the rewrite a chance. Because it is using normal esphome UART definition, you can specify your pins there, maybe it helps. See https://github.com/kotope/valloxesp/blob/esphome/example_vallox.yaml , you shouldn't need to copy any files, just use the external component part and the rest as written , it should use the files from the correct branch here.

If it doesn't work you can also uncomment the debug part in the UART. (maybe with "after: bytes: 6" instead of 1)..

sleepymaxx commented 11 months ago

Hi sorry for my late reply -family silvester + work as firefighter... so a little to less time these days.. -- i will try your workaround maybe today latest tomorrow.. i have to reassemble my whole esp and to make some changings in the hardwiring... i will post all writings and all logs as soon as possibile Thank you again for your great work (in advance ;-) )

sleepymaxx commented 11 months ago

Good evening and a haapy new year. Installed all got all sensors in my Home Assistant but without any relevant data inside of it.

Tested: changing RX / TX (pin change) Tested: external components copied locally Tested: external components integrated by source over github Tested: debug code on and off

Results: Every sensors dont give any relevant data () Results: the lights on the module are flashing in low mode..

My vallox is already working fine over the vallox original FDB 382 log of my esp run is attached. Thanks in advance... logs_wasseruhr-esp_run(2).txt

github-k8n commented 11 months ago

In your log it shows that you have serial logging enabled [17:29:01][W][uart.arduino_esp8266:127]: You're using the same serial port for logging and the UART component. Please disable logging over the serial port by setting logger->baud_rate to 0.

Please disable local serial logging by adding the following to your devices yaml file:

logger:
  baud_rate: 0
github-k8n commented 11 months ago

Oh, and I guess you should also define "devicename" in your yaml :) .. i just copied that from my config.. In your case you could add this to your yaml:

substitutions:
  devicename: wasseruhr-esp
sleepymaxx commented 10 months ago

Good evening, substitutions: is a order wich is not allowed in Home Assistant.. so here no better results

github-k8n commented 10 months ago

Can you paste (as file) your yaml config for the esp device and I'll send back the correct config?

sleepymaxx commented 10 months ago

Here you go: Config of Wasseruhr yaml: (had to rename it becaus of lack of support of uploading .yaml files so only exchange .txt with .yaml) to txt.: wasseruhr-esp.txt Latest logfile... : logs_wasseruhr-esp_logs(1).txt

github-k8n commented 10 months ago

According to the log, the data is being sent but we do not receive any answer. My guess is that something is wrong with the cabling. Logs show: TX Pin: GPIO3 RX Pin: GPIO1 You are sure that you connected them correctly to GPIO3 and GPIO1? (if you have them connected elsewhere then you can just specify the GPIO instead of using the RX/TX definitions which are device-dependent) Maybe try reversing them to see if things improve (typically if you connect devices you connect TX -> RX and RX -> TX , don't remember if here it was really TX -> TX as in kotope's description.... )

As for the rest, if you don't use substitutions (not sure why it wouldn't work for you, remeber we are talking about esphome, not HA substitutions.. https://esphome.io/guides/configuration-types.html#substitutions ) just name the sensors according to your taste. Attached is the yaml file with some small changes (debug after 6 bytes makes it easier to read and changing the names of the sensors) wasseruhr-esp.txt

sleepymaxx commented 10 months ago

correct i used GPIO1 TX and GPIO3 RX (and tested also vise versa) grafik okay will test if the GPIO commands will funct. the naming of the sensors will have time... so when there is all funcioning i will go for the names and kill the old data of the wrong ones ;-)

github-k8n commented 10 months ago

Reg the RS485 module, you should see it quickly blinking if some data is transmitted. Also I recommend to just connect it to the connectors on top of the device (see page 12 on the lower left here: https://vallox.de/wp-content/uploads/2023/09/BA_ValloPlus-350SE_2015-03.pdf ), it is less fiddly than playing around in the controller.. not sure if you already did it that way .. (also make sure you have A and B connected correctly and not reversed, maybe try reversing on that side too..?)

sleepymaxx commented 10 months ago

Good evening, Changed my yaml according to your recommendations afterwards Tried the following: [TX (Vallox) to TX (RS485) and RX (Vallox) to RX (RS485)] & [TX (Vallox) to RX (RS485)and RX (Vallox) to TX (RS485)]

i changed in both configurations also the naming in the Yaml file for Tests: tx_pin: GPIO1 rx_pin: GPIO3 and tx_pin: TX rx_pin: RX

i changed in every configurations the RX/TX (RS485) to ESP pins:

Also i remembered the problem mentioned here and tested this configuration with both options mentioned above: I tested also to give my ORINALLY installed Controller (FDB 382) a other Bus Adress (i changed it to 2) because so you wont get a bus error... but also no positive changings...

Results: either the RX or the TX led of my RS485 module are blinking (accordingly to connected pins from my ESP8266 D1mini) and the logfile is putting out very much (uart debugs): logs_wasseruhr-esp_run(3).txt in this moment i have no more ideas... perhaps my RS485 module is broken (but if its so it shoudn´t blink)?

github-k8n commented 10 months ago

Don't :D

Does the RS485 blink quickly in bursts? or just slow on/off ... If any data is received you should see the bursts coming in .. also if you change anything (increase temperature or change fan speed on the originally installed controller) you should see additional quick flickering of the led

Thus, my suggestion: Try completely without the esp, just connect the RS485 modules (make again sure that A and B are connected correct and the module has power (GND and VCC) you should then see the RX led blinking quickly every few seconds from the data the mainboard is sending out... (and as mentioned, I would not play around inside the original controller, just use the connectors on top...)

sleepymaxx commented 10 months ago

quickly in bursts with pauses of around 2-5s sec. (the pauses are always the same length also as the bursts... )

github-k8n commented 10 months ago

If it is still connected to the ESP then the bursts are from the esp, that is good. However we do not see any data from the RS485 bus which means that there is something wrong there

Maybe try reversing A and B on the RS485 side of the module...... the TX/RX side of things is clearly working ...)

(if you have an oscilloscope you could check the a/b lines for signals without anything connected other than the original controller...)

qvr commented 10 months ago

Hmm, I had a feature ready for the esphome branch to reset the service counter via esphome integration, but I now see that @github-k8n 's PR#34 has basically removed my previously merged features (#27 and #29). Was this intended?

github-k8n commented 10 months ago

Basically did a complete rewrite to clean it up and make it work better (as external module etc..) I can have a look tomorrow at the previous merges to integrate them...