Dynamic Configuration Variables

Hello,

I’m using ADS115’s to measure the resistance of PIR motion sensors. To get an accurate reading I have to define the reference voltage as a configuration variable. The challenge is that the voltage fluctuates by 0.1-0.3v. Although this is manageable, I’d like the ability to dynamically set the reference_voltage. I have set up a sensor to capture the reference voltage but can’t find a way to then copy that state to a configuration variable.

Here is an extract from my esphome yaml:

  - platform: resistance
    sensor: source_sensor1
    configuration: DOWNSTREAM
    resistor: 5.6kOhm
    name: Resistance Sensor1
    reference_voltage: 5.5
    id: resistance_sensor1

It’s the reference_voltage: 5.5 section I’d like to be able to copy the values from another sensor.

Any help would be appreciated.

I’m doing exactly what you need with a temperature sensor. It exposes a number helper to Home Assistant where I can set the temperature offset dynamically.

It’s using a filter here in this example:

sensor:
  - platform: bme280
    temperature:
      id: TEMPERATURE
      filters:
        - lambda: return x + id(TEMPERATURE_OFFSET).state;

number:
  - platform: template
    id: TEMPERATURE_OFFSET
    entity_category: config
    optimistic: true
    step: 0.5
    min_value: -5
    max_value: 5
    restore_value: true
    initial_value: -3.0

I think what you would need would be something like this:

number:
  - platform: template
    id: REF_VOLTAGE
    entity_category: config
    optimistic: true
    step: 0.5
    min_value: 0
    max_value: 10
    restore_value: true
    initial_value: 5.5

sensor:
  - platform: resistance
    sensor: source_sensor1
    configuration: DOWNSTREAM
    resistor: 5.6kOhm
    name: Resistance Sensor1
    reference_voltage: !lambda 'return id(REF_VOLTAGE);'
    id: resistance_sensor1
1 Like