different areas
For example, combine the atmospheric pressures from various sensors into a single mean value (or other transformation) for passing on to the Home Assistant UI and connected databases.
Do I:
attach the necessary code to the .yaml of one of the existing devices and pull in the data from all the other sensors, or
do I create some sort of virtual device that combines, then manipulates, the data for output
You’re going to need to do template sensors for the math and/or mqtt sensors for the math and to attach the sensor to a device. Helpers (template sensors among them) can not be attached to a device, but you can attach an mqtt sensor (you’ll need an mqtt broker up and running) to a device by the device’s id (which can typically be found in the advanced diagnostics of a device).I attach mqtt sensors to the energy monitoring smart plug I use with automations to publish device status, last_completed_and last_emptied for my washer and dryer.
What are you trying to accomplish?
ESPHome config?
Trying to build an Automation or script?
trying to build an app? (add-on)
Trying to build an integration?
I have two BME688 devices attached to the same ESP32 device and referenced in the same configuration code. Since the entities are ‘local’ to the config code I can reference them easily, eg., for the mean:
I can also obtain the local meteorological data for comparison, but when I try to, say, calculate the difference between the mean, above and the published met office value I run into the problem of how to reference a sensor not ‘local’ to the code:
It’s that last reference I can’t figure; the former is easy because it’s defined in the previous block. I’ve also tried ‘sensor.met_office_yorkshire_pressure’ but that’s also a no-no.
I’m trying to extend an ESPHome configuration, see my further comments regarding referencing ‘non-local’ sensor state data.
{‘non-local’: Not sure what terminology to use, I’m used to to C++ style referencing where variables are local to a function and are not visible outside that function or, if no other way, ‘globals’ can be referenced anywhere}
I think the issue is that ‘met_office_yorkshire_pressure’ exists only as an integration within Home Assistant and not ESPHome.
The issue is definitely with referencing the entity in HomeAssistant. Prefacing the id with ‘sensor.’ (as in 'sensor.met_office_yorkshire_pressure) reveals a useful error message regarding use of the homeassistant platform. Here’s my latest:
OK, it seems the platform: homeassistant is there just to bring in the entity from HomeAssistant whereupon it can be given a new local id. That local id can then be used in the template platform to undertake the calculation. This seems to work:
- platform: homeassistant
name: "BME688 Pressure Variance"
id: met_local_pressure # new local id
entity_id: sensor.met_office_yorkshire_pressure # from HomeAssistant
- platform: template
id: press_var # the 'local' entit to which is assigned the state value of 'sensor.met_office_yorkshire_pressure'
unit_of_measurement: hPa
device_class: "pressure"
state_class: "measurement"
accuracy_decimals: 1
lambda: 'return id(bme688_mean).state - id(met_local_pressure).state;'