I (mostly) get how you can create a custom sensor so you can display the current value of something from ESPHome to Home Assistant, but what if I want to write back to a variable for use in a lambda?
For example, when calculating a flow rate I need to count the number of cycles equal to one cubic foot. On my meter that happens to be 8, but when sharing the code I’d like to be able to let people adjust this from HA instead of having to change some values in the code and upload it fresh.
Is it possible to write data back to a variable in ESPHome from Home assistant?
You’d make an ESPHome number entity that you’d expose to HA. Automate using that entity. You can control that entity from HA.
You can also access an HA sensor, but to me that’s backwards and too coupled. You’d make an input number in HA, wrap it in an HA template sensor and access that from ESPHome.
Okay so I made a number entity, and at first glance it looks okay, but it updates once and then never updates again on the home assistant side. I know it’s updating in the lambda area elsewhere in my code since my math calculations are coming out correctly, but it’s not updating the value as shown in HA.
Not sure what you mean here. When you say “updates” are you changing it on the ESP device?
Number entities on the ESPHome device can be updated using number.set: etc, or via lambda using make_call(). On the HA side they are an entity that can be updated on the dashboard or using developer tools.
Either way, an update on one side is always reflected on the other. Updating the entity in HA updates the value on ESPHome and vice-versa.
Its being changed on the esp device in a lambda, but the change isnt reflected in home assistant.
Can you give an example of the number.set or lambda make_call? I read the example on the esphome number template, but in that example, it was a hardcoded number.
Currently in an interval lambda i do a
Id(variable).state = math goes here
To change the value, but after that change I’m at a loss on how to get HA to reflect the change to that number template variable.
Thank you! I kept trying to search for information on the Number Template and ending up in areas that just never quite gave the information to do this. I set up two “autos”
auto maxCall = id(gas_max).make_call();
auto minCall = id(gas_min).make_call();