Hi all, I am following the rocky road of learning to configure esphome and so far its been a royal pain.
I am trying to develop a water meter monitoring system since our cost has gone through the roof.
I have read multiple posts related to similar situations but none have really addressed the input number in a homeassistant service. I have searched thought the online manual but came out empty.
I already have a number helper in HA named input_number.total_watter_consumption_global. The HA service is not working and was hoping someone might be able to shed some light in what I am doing wrong. What I am trying to implement so far is a interval call that executes a script which updates this number helper with the current reading of the “water_meter_total”.
I chose to go this route of using a HA helper rather than a global saved to the flash since I didn’t see the advantages of the latter.
Here is my code. Any help would be appreciated.
Is this number visible by Home Assistant? The reason I used the input_number helper was because I will need to read this number in a Home Assistant automation which will indicate how much water each irrigation zone is consuming.
From the code above this is the code I am not sure it works, because I’m not sure it does anything.
Idk where you were getting reference information but, you’re making this far more complicated than it actually is.
You just need to set up the pulse meter/counter and the pulse total part of the config and thats it…
The script and HA sensor your importing, all the stuff you’ve got commented out is completely unnecessary.
Sensor values, state changes, etc, etc are sent to HA all by itself. Its not necessary to set that up manually with scripts or on_boot automations and will likely just cause more problems and more troubleshooting…
Try takong bite sizes on projects and get a feel for how things work instead of trying to get it all done in 1 go.
The reference information I got from all the other posts and tried to modify them for my needs.
The issue I have is that after a power cycle of the ESP32 the total number of gallons gets reset, so the idea was to save the “water_meter_total” into the input_number helper, every 10 seconds, and on the new power cycle of ESP32 to have “water_meter_total” restored from input_number helper.
This saving of the “water_meter_total” into the input_number helper is what is no working.
If I am to re-enable this line of code:
then I can see that ha_water_meter_total gets update with the value of water_meter_total since I log it with:
- lambda: |-
ESP_LOGD("main", "Value of water_meter_total is %f ", id(water_meter_total).state);
ESP_LOGD("main", "Value of HA total_water_consumption_global is %f ", id(ha_water_meter_total).state);
however the actual total_watter_consumption_global from HA doesn’t get updated. Reading online that I will have to use a homeassistant service in order to get the update, that’s what I tried to use above.
However that doesn’t work. I must be doing something wrong in the configuration of that service.
I couldn’t find any online reference for the options available for “service: input_number.set_value” and just tried things, however nothing worked.
Was either using this approach or writing to flash the total gallons every few seconds and restore it upon reboot. I choose to use the first one since I would not wear out the flash.
Forgot to mention that everything related to the sensors pulse_counter and pulse_meter already shows correctly in HA. That’s what I started with so I did take the bite size approach already. Is just this last part that I couldn’t get it to work yet.
I went ahead and implemented the code changes to use the number component. Everything works however on reboot of ESP32, the number component which is supposed to hold the last value, gets reset as well.
Since the number helper doesn’t get reset on reboot, I will have to come back to using it instead.
So my request for help with the above mentioned code still stands.
Thank you for the suggestion, but it doesn’t work. Upon power cycle the number component still gets set to 0. Isn’t “restore_value” having to do with restoring from flash? I am not doing any writes to the flash so that it can be restored from there. Am I missing something?
Here is my latest configuration with number component:
I blew air in the water sensor to simulate water flow. I got a reading of 1.496gal rounded by the display to 1.5gal. I could see from the log that the value of the global is set to 1.496gal
I sat at this reading for 10minutes, so I should have had 10 saves to the flash of the value 1.496.
Then I power cycle the ESP32 and I observed the first read from the flash of the global is 0.111901:
I was expecting only the global to have the value saved, but it looks like both the global “total_gallons” and water_meter_total got “saved” but when read back both are at 0.111901, nowhere close to the last value of 1.5
I took you advice and implemented your changes, but I had to make a few of mine.
I cannot use water_pulse_meter actually water_pulse_meter_gal_per_minute because that’s not what I’m trying to restore. water_pulse_meter_gal_per_minute gets set to 0 if no pulses are detected for a minute.
What I want to save is water_meter_total and for that I have no .set_total_pulses option. so I had to use a lambda expression.
That being say, not matter what I try in “on_boot”, water_meter_total doesn’t get restored. I tried with/without priority, with/without wait_until, it looks like the lambda expression doesn’t get executed. That is also confirmed by the fact that I don’t see the log " on_boot:Restoring globals"
I am out of ideas. Here is the code again.
I finally figured it out. @zenzay42 you were correct about pulse_meter.set_total_pulses;
Here is the final code if anyone needs a reference.
P.S. set logger to NONE and remove the debug code
Were you trying to store the running total on the esp board as well? I dont think I understood your question to begin with. I just assumed you were storing that data in HA like just about everyone does because it adds up a total and stores that data as well. For example, here is mine. It just takes the data from the esp node and its then tracked and seperated by time frames.