How to increment hassio counter from esphome switch

Hi
I made myself a syrup dispenser with a WEMOS and a peristaltic pump in ESPHome, that pumps for 4 seconds and reverses for 300ms (to avoid dripping afterwards). Now I would like to have a counter in hassio, that I can reset once a month (just for the fun of it), which is incremented from ESPHome, so I don’t have to add another automation for this.
my question: how can I tell hassio to increment a counter from an ESPHome device?
Here’s the ESPHome yaml:

output:
  - platform: gpio
    pin: D1
    id: pump1_forward
  - platform: gpio
    pin: D2
    id: pump1_reverse

switch:
  - platform: output
    output: pump1_forward
    name: "Pump 1"
    id: pump1
    on_turn_on:
      then:
        - output.turn_on: pump1_forward
        - delay: 4s
        - output.turn_off: pump1_forward
        - output.turn_on: pump1_reverse
        - delay: 300ms
        - output.turn_off: pump1_reverse
        - switch.turn_off: pump1

thanks.

hello

sensor:
  - platform: homeassistant
    entity_id: input_number.mysensor #create this 'helper'  in hassio
    name: mydummysensor
    id: mydummysensor
    internal: true

on......:
  then:
    - homeassistant.service:
        service: input_number.set_value
        data:
          entity_id: input_number.mysensor
          value:  !lambda |-
            return id(mydummysensor).state +1;

to reset it each month u need to set the time:

time:
  - platform: homeassistant
    id: homeassistant_time
    # ...
    on_time:
      - seconds: 0
        minutes: 0
        hours: 0
        days_of_month: 1
        then:
         - homeassistant.service:
           service: input_number.set_value
           data:
             entity_id: input_number.mysensor
             value:  0

or with a switch:

switch:
  - platform: template
    name: "Template Switch"
    turn_on_action: 
      - homeassistant.service:
          service: input_number.set_value
          data:
            entity_id: input_number.mysensor
            value:  0
2 Likes

wow, it works like a charm, thanks. I very much appreciate the quick and complete answer :slight_smile:
although I had to put ‘’ around value, didn’t quite understand why, but it works:

value: '0'

greetings,
Hugo.-

This is an old topic, which actually helped me. But I found a simpler answer. Just add this code in your YAML configuration and should do the trick. No local variables needed.

        - homeassistant.service:
            service: counter.increment
            data:
              entity_id: counter.my_counter # Helper must be added to Hassio