ESPHome - reading/incrementing output value

I have no idea if this has been asked before (I could not find it) but… I am trying to increment the value of an output, an esp8266_pwm specifically and I am using a binary sensor, a button linked to GPIO0, to register when I want the output to increment. The trouble I am having is that there seems to be no way to either read the level of the output (in order to add to its value) or to just increment it directly.

Is this something that just doesn’t exist yet or am I using the wrong objects?

binary_sensor:
  - platform: gpio
  pin: 
    number: GPIO0
    inverted: True
  id: button
  on_click:
    then:
      - output.set_level: 
          id: pwm
          level: ##### I would like to increment the outputs level here ####
output:
  - platform: esp8266_pwm
    pin: GPIO13
    id: pwm

Thanks!

EDIT: Apologies, I am trying to accomplish this within the ESPHome framework itself. If I can leave home assistant out of the simple automations (incrementing the output level) than that would be preferable.

I’m wondering whether you really need a counter?

But then I may be misunderstanding your question?

where did you get this?
Doesn’t look like this is a valid parameter for a gpio binary_sensor.
Might need an automation and as @wellsy mentioned use a counter to increment the value

I think OP is referencing the yaml code for the esphome device (which has limited support for on-device automations) and not homeassistant yaml/autos.

Suggest either moving automation to homeassistant and using a counter or posting question on using esphome framework in one of the support places for that software.

@wellsy That is a home assistant object. I am trying to accomplish this all within ESPHome so that if my home assistant instance goes down or the network is down the button will still increment the pwm level. If I was to go the route of using home assistant objects than I would read the value directly from there.

@lolouk44 It is valid within ESPHome, its not a home assistant object itself

@brahmafear Yes, that is correct. I can move it to home assistant but the wife test says the tech has to work independent of the server or the network (ie. the button should do button things as long as the power is on)

As far as the support places for ESPHome, that is what I thought this was for specifically (I used the esphomelib tags). I have seen most if not all the trouble shooting and questions for esphome here on this forum. If I am in the wrong place than I apologize.

No worries - and understand request to keep functionality localized.

The new discord channel for esphome might be best place to ask. Lots of esphome knowledge there.

1 Like

Use a global variable to store the current level and increment it each time the level is set:

then:
  - lambda: 'id(glob_var) += 0.1;'
  - output.set_level:
      id: pwm
      level: !lambda 'return id(glob_var);'
4 Likes

I’m not getting back to look at this till sunday, but thanks I will give it a shot!!

This worked perfectly! Thank you! I had been trying globals but i was not aware I could return a value in a lambda and use it to set something.

Thanks again!

Hi Otto - is this how I would increment a counter, too? I can do this from within HA like so

    action:
      - service: counter.increment
        entity_id: counter.number_of_people

Thanks!