HA Glow without input from a pin (but a binary sensor)

I would like to build a Glow devide to get energy and power readings from my ferraris meter - I use a TCRT5000 (in analog mode - digital didn’t work at all) to spot the red part of the disk and have it turn on/off a binary sensor.

Now I would like to use this binary sensor in the pulse_meter (and total_daily_energy) sensors … however, they seem to require me to set a pin

sensor:

  - platform: adc
    id: pulse_raw
    pin: GPIO32
    raw:  true
    internal: true
    update_interval: 50ms
    filters:
      - sliding_window_moving_average:
          window_size: 3
          send_every: 1
    on_value_range:
      - above: 345
        then:
          - binary_sensor.template.publish:
              id: one_turn
              state: ON
      - below: 300
        then:
          - binary_sensor.template.publish:
              id: one_turn
              state: OFF




  - platform: pulse_meter
    name: '${device_name} - Power Consumption'
    id: sensor_energy_pulse_meter
    unit_of_measurement: 'W'
    state_class: measurement
    device_class: power
    icon: mdi:flash-outline
    accuracy_decimals: 0
    pin: ${pulse_pin}
    # internal_filter: 100ms
    filters:
      # multiply value = (60 / imp value) * 1000
      # - multiply: 60
      - lambda: return x * ((60.0 / 75) * 1000.0);
    total:
      name: '${device_name} - Total Energy'
      id: sensor_total_energy
      unit_of_measurement: 'kWh'
      icon: mdi:circle-slice-3
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        # multiply value = 1 / imp value
        # - multiply: 0.001
        - lambda: return x * (1.0 / 75);


binary_sensor:

  - platform: template
    internal: true
    id: one_turn

I’m out of ideas (other than physically connecting one pin to another and pulling it up every time the sensor turns on … I would really like to avoid that)

So, I ended up doing exactly that with a switch and it works well so far … but it feels really wrong

I physically connected pin 18 to pin 16:

sensor:

platform: adc
    id: pulse_raw
    pin: GPIO32
    raw:  true
    internal: true
    update_interval: 20ms
    filters:
      - sliding_window_moving_average:
          window_size: 3
          send_every: 1
    on_value_range:
      - above: 320
        then:
          - switch.turn_on: one_turn
      - below: 290
        then:
          - switch.turn_off: one_turn

  - platform: pulse_meter
    name: '${device_name} - Power Consumption'
    id: sensor_energy_pulse_meter
    unit_of_measurement: 'W'
    state_class: measurement
    device_class: power
    icon: mdi:flash-outline
    accuracy_decimals: 2
    timeout: 20min # default = 5min
    pin: 16
    # internal_filter: 100ms
    filters:
      # multiply value = (60 / imp value) * 1000
      # - multiply: 60
      - lambda: return x * ((60.0 / 75) * 1000.0);
    total:
      name: '${device_name} - Total Energy'
      id: sensor_total_energy
      unit_of_measurement: 'kWh'
      icon: mdi:circle-slice-3
      state_class: total_increasing
      device_class: energy
      accuracy_decimals: 3
      filters:
        # multiply value = 1 / imp value
        # - multiply: 0.001
        - lambda: return x * (1.0 / 75);


switch:
  - platform: gpio
    pin: 18
    id: one_turn
    internal: true

Still, is there a more elegant solution?

Probably not. You could write your own C++ code to use the binary sensor changes in a lambda, to calculate the energy based on your readings.

But if your programming skills aren’t up to it, what you have is simpler.

Yeah I’ll just stick with my solution for now. It seems to work very well and I doubt, me trying to code something like that would result in anything useful :woman_shrugging: