ADC to trigger multiple outputs based on voltage

You have previous_track in your lambda but the id is previous_trk

          else if ((id(adc_sensor).state > 7.5) and (id(adc_sensor).state <= 9.5)) {
              id(previous_trk).toggle();
          }

also the colon after on_turn_on


  - platform: gpio
    pin: GPIO22
    id: previous_trk
    name: "previous_track"
    inverted: true
    on_turn_on:
        then:
          - delay: 200ms 
          - switch.turn_off: previous_trk ##relay_1

I think I got it,

Tomorrow I will install and test.

Thank you very much for your help! Much appreciated!

1 Like

Hey guys!

Installed today, all works well except volume down. Its a bit weird as I had tested everything using relays and confirmed that all relays were switch.

The only thing I changed was the values in the lambda for the ADC.

My full code is.

sensor:
  - platform: adc
    pin: 34
    name: "VCC Voltage"
    id: adc_sensor
    update_interval: 0.3s
    attenuation: auto
    filters:
      - multiply: 3.3
    on_value:
     then:
       lambda: |-
         if (id(adc_sensor).state < 1) {
             id(next_trk).toggle();
         }
         else if ((id(adc_sensor).state >= 2) and (id(adc_sensor).state <= 3)) {
             id(previous_trk).toggle();
         }
         else if ((id(adc_sensor).state > 8) and (id(adc_sensor).state <= 9)) {
             id(vol_down).toggle();
         }
         else if ((id(adc_sensor).state > 5) and (id(adc_sensor).state <= 6)) {
             id(vol_up).toggle();
         }

switch:
  - platform: gpio
    pin: GPIO17
    id: vol_up
    name: "volume_up"
    inverted: true
    on_turn_on:
      then:
      - delay: 200ms 
      - switch.turn_off: vol_up

  - platform: gpio
    pin: GPIO16
    id: vol_down
    name: "volume_down"
    inverted: true
    on_turn_on:
      then:
      - delay: 200ms 
      - switch.turn_off: vol_down

  - platform: gpio
    pin: GPIO21
    id: next_trk
    name: "next_track"
    inverted: true
    on_turn_on:
      then:
      - delay: 200ms 
      - switch.turn_off: next_trk

  - platform: gpio
    pin: GPIO22
    id: previous_trk
    name: "previous_track"
    inverted: true
    on_turn_on:
      then:
      - delay: 200ms 
      - switch.turn_off: previous_trk

You can try increasing the delay. You can also add

logger: 
  level: VERY_VERBOSE

After the upload, leave the log running. Then trigger the switch to see what it logs for the event.

1 Like

Its weird, it appears to be triggering. However, it does not work.

I have confirmed that if I short GPIO16 which is volume down, that the volume goes down, so from there everything is working fine.

[00:01:11][D][sensor:094]: 'VCC Voltage': Sending state 10.42319 V with 2 decimals of accuracy
[00:01:12][VV][scheduler:226]: Running interval 'update' with interval=300 last_execution=7334 (now=7634)
[00:01:12][V][adc:148]: 'VCC Voltage': Got voltage=2.5112V
[00:01:12][V][sensor:043]: 'VCC Voltage': Received new state 2.511174
[00:01:12][VV][sensor.filter:014]: Filter(0x3ffb99f8)::input(2.511174)
[00:01:12][VV][sensor.filter:021]: Filter(0x3ffb99f8)::output(8.286875) -> SENSOR
[00:01:12][D][sensor:094]: 'VCC Voltage': Sending state 8.28687 V with 2 decimals of accuracy
[00:01:12][D][switch:020]: 'volume_down' Toggling ON.
[00:01:12][D][switch:055]: 'volume_down': Sending state ON
[00:01:12][VV][scheduler:032]: set_timeout(name='', timeout=200)
[00:01:12][W][component:237]: Component adc.sensor took a long time for an operation (56 ms).
[00:01:12][W][component:238]: Components should block for at most 30 ms.
[00:01:12][VV][scheduler:226]: Running timeout '' with interval=200 last_execution=7680 (now=7880)
[00:01:12][D][switch:016]: 'volume_down' Turning OFF.
[00:01:12][D][switch:055]: 'volume_down': Sending state OFF
[00:01:12][VV][scheduler:226]: Running interval 'update' with interval=300 last_execution=7634 (now=7934)
[00:01:12][V][adc:148]: 'VCC Voltage': Got voltage=2.5232V
[00:01:12][V][sensor:043]: 'VCC Voltage': Received new state 2.523162
[00:01:12][VV][sensor.filter:014]: Filter(0x3ffb99f8)::input(2.523162)
[00:01:12][VV][sensor.filter:021]: Filter(0x3ffb99f8)::output(8.326436) -> SENSOR
[00:01:12][D][sensor:094]: 'VCC Voltage': Sending state 8.32644 V with 2 decimals of accuracy
[00:01:12][D][switch:020]: 'volume_down' Toggling ON.
[00:01:12][D][switch:055]: 'volume_down': Sending state ON
[00:01:12][VV][scheduler:032]: set_timeout(name='', timeout=200)
[00:01:12][W][component:237]: Component adc.sensor took a long time for an operation (56 ms).
[00:01:12][W][component:238]: Components should block for at most 30 ms.
[00:01:12][VV][scheduler:226]: Running timeout '' with interval=200 last_execution=7980 (now=8186)
[00:01:12][D][switch:016]: 'volume_down' Turning OFF.
[00:01:12][D][switch:055]: 'volume_down': Sending state OFF
[00:01:12][VV][scheduler:226]: Running interval 'update' with interval=300 last_execution=7934 (now=8238)
[00:01:12][V][adc:148]: 'VCC Voltage': Got voltage=3.1585V
[00:01:12][V][sensor:043]: 'VCC Voltage': Received new state 3.158542
[00:01:12][VV][sensor.filter:014]: Filter(0x3ffb99f8)::input(3.158542)
[00:01:12][VV][sensor.filter:021]: Filter(0x3ffb99f8)::output(10.423188) -> SENSOR
[00:01:12][D][sensor:094]: 'VCC Voltage': Sending state 10.42319 V with 2 decimals of accuracy

Did you try increasing the the delay?

Sure, I will try that.

Ok I just tried increasing the delay to 1s, didnt work.

Also, I have enabled the web interface on the esp23, however, the only options in the web interface are OTA and WiFI.

There is no option to manually trigger the outputs or switches from there? Or even view the logs,

This way I can manually trigger the output to see if that works, then I will know it is an issues with the ADC part.

Any reason why I have such limited web UI options?

Thanks

ok so I was able to get the web interface working,

Upon doing so, I connected to the devices we interface, and pushed the volume down button, sure enough I could see the output momentarily turning on and off.

So, im in a situation where I have manually shorted GPIO16 to GND on the ESP32, and volume goes down, confirmed that everything from there back works.

And I have now confirmed that my switch is switching GPIO16 on the ESP when the volume down button is pressed.

So where does that leave me?

Iā€™d try to switch the volume down gpio with the volume up gpio in the yaml. This will show if GPIO16 can control the up relay and if the up gpio can control the down relay. This will help narrow it down potential causes.

I have tried changing the GPIOs in the code to switch the relays,

To see if the volume_down would trigger the volume_up, have not tried changing the physical wires on the ESP for the outputs.

It must be something to do with the output not switching or switching incorrectly on the ESP as the code is working as expected, and shorting the wires does trigger a volume_down event.

Ill do some more troubleshooting tonight.

I switched from GPIO16 to a 23 and now its working, not sure what that was about.

Thanks for the help.

1 Like