I am trying to control ESPHOME calibrate_linear values using HA.
I am recieving PH data vrom my ads1115 module and doing the initial callibration with calibrate_linear filter. My code looks like this:
I want to calibrate it using home assistant. I was thinking about global variables, but I can not understand how to implement it using HA. I would create the input number component in home assistant, then would apply the value of it to the sensro. In ESPHOME I would create the homeassistant component which would read the value of the sensor. But how can I assitn it to the map value from sensor in the calibrate linear of the ESPHOME?
Or maybe it is better to get raw data from ESPHOME and then calibrate it in homeassistant?
My personal experience with linear calibration for current and power is not very positive… I think the algorithm “close to 0” does not calibrate very well and despite me also having 0 -> 0 makes it display negative values when it should be 0.
Hello,
i 've run into the same problem as you. And also to calibrate a pH probe linear to the ADS voltage.
Did you find any solution for your calibration from HA?
As far as i am in my research seems calibration_linear isn’t “templatable” :-/
so we can’t use (global) variables …yet. Hopefully in a soon coming update
Old thread, but for those coming from a search engine:
Just report back the voltage to HA, then use a template sensor to do the linear calculations yourself. You can utilize helpers like ph_calibration_voltage_7, 4 and 10. Then just update those values when you go to recalibrate.
I’m implementing the PH Sensor and reporting mV to HA, have created all helpers needed, but the formula is scaping me.
I found a page with some implementation, but does not have a explanation about the formula. Could not get it to work yet, since my sensor mV returns voltage very below from what the code asks. I need to adapt. I’m not using a ADS, and put a divider from the sensor to drop voltage to 3.3V, my ESP limit.
So, here is the formula (template sensor). I don’t know what is xa, xc, ya, yb, etc… :
You are using ADC with the esphome sensor or else you wouldnt be reading anything at all. The only way you can read an analog sensor is by using an Analog to Digital sensor because everything else is Digital and can only be 1 of 2 states, On/Off or 0.0v - 3.3v so Digital could be 0v/Off or 3.3v/On while analog can be 0.0v and any other voltage between 0 and 3.3v like, 1.4v, 2.6v, 3.1v etc. Thats what allows you to read a voltage while Digital would be more for something like a switch that is On or Off only.
You need to include more details with posts like this too. What esp board are you using? Did you verify the voltage output of the divider or did you just follow a guide when making that too? Do you even have the sensor wired to a GPIO that is capable of reading Analog? Most boards can only read ADC on a few pins and the esp8266 only has 1 Analog input available so, you should probably address those questions and then post YOUR yaml code! It doesnt do any good if we can only see the code from where you copied it.
What exactly are you trying to do with this unnecessary template sensor and a HA template sensor? You dont need to duplicate it by taking the sensor value and using it to create a 2nd one just to do some automations.
You also dont need to, nor should you want to adjust values for calibration of the filter
- calibrate_linear:
This is something that should be calibrated and then its done, its calibrated and doesn’t require ongoing maintenance. You shouldn’t have to be recalibrating some sensor so frequently that you need to do it from the HA UI and if that is somehow the case then, you most likely have some other problem that needs addressed.
That’s definitely part of the problem! You dont need to “find some page” to copy code from and especially if there’s no explanation and you dont even understand the code, of course it doesnt work…
There is official Esphome and Homeassistant documentation that explains all these things and provides examples like so…
Now you dont need to go around copying random code or whatever some Chatbot spits out which is even worse most times.
Looking at the guide where you got some questionable instructions, they dont even talk about or explain why they added variables for calibration in HA and it really doesnt make any sense. You have to be careful blindly following guides or instructions from online strangers because any nut job can post a guide that instructs you to accidentally electrocute yourself! Anyone can post guides and there’s no one checking them or correcting bad ones on the internet
I’m not blind following anything. That’s why we come here looking for help/advise/information. Placing ideas to see what more experienced people can talk about.
It was not me who first posted this doubt, but for me, it would be handy this feature. Those pH Sensors do require calibration often. I cannot say the frequency, but it discalibrate with time. Hardcoding the calibration works, but if we could do everything inside HA and not having to recompile and reinstall on ESPHome everytime we do a calibration would be better (for me, at least).
When I said I was not using a ADS I meant an external one, like ADS1115, of course I’m using the internal ADC, with input on analog A0 (in my case). The topic is clear saying we are talking about ESPHome, and independently if its a ESP8266 ou a ESP32, the code should be the same regarding the calibration parameters.
The code I posted was to give a idea of a possible solution, since calibrate_linear cannot use a variable and changed deirectly inside HA, so HA should be responsible for all calculations, and leave ESPHome returning just the readings. It’s not duplication code.
You fooled me then, it sure looks like a copy/paste job.
Ya? Well, you should have said you were an authority for all ph sensors available on the market and for all of them so broadly. Someone should tell the guys paying $100’s for each sensor when the 3$ ones are apparently the same if i understood that correctly.
I can only go by the statements you made and that seems pretty clear to me. Much clearer than your attempt to suggest
Somehow really means you are using an ADC but its not an external ADC because, you think that somehow makes a difference if its onboard or an expander, even though they are both clearly an ADC and do exactly the same thing.
Oh, is it clear and is specific that were discussing Esphome? Thats what I thought too and its the reason I was asking about your Homeassistant template sensor you posted which is not the syntax Esphome uses…
So, dont even use calibrate_linear, then you wont have the problem with accepting a variable or messing with whatever that mess of a template sensor was that you posted and is unnecessary irregardless.
If you want to create a UI in HA to change calibration settings for that sensor or any sensor, ypu really dont want to intentionally split them up so that neither the esp or HA can perform this action without the other and if either is not working(HA, Esphome) then you cannot perforn the action you need… I sometimes use an example like, “if you had to replace the spare tire on your car. How much sense would it make to put that spare tire in the back of your wifes car instead of yours?”
Ya, you’ve still got a spare but, its useless to you if your wife doesnt follow you around with it because, the day you get a flat and need it, its unavailable because another system stores it for ypu so, your screwed when the day comes when 1 breaks.
Esphome physically reads the sensor, its used for calibration and there’s absolutely no reason to push the calculations to HA because the esp board is perfectly capable of doing them and is perfectly capable of operating 100% independent of HA…
Calibrate linear is just a shortcut function so that users dont have to manually input variables and do some algebra to solve the eqation. If you cant use the “shortcut function” then just look up how to solve linear eqations and there you go!