I have an ESP32 controlling another system by sending 100 ms pulses. If the pulse is close to 100 ms, the system counts it. By sending a pulse, waiting more 100 ms and sending another I can make it count 2, and so on.
It was a very simple task to do with arduino, but I am struggling with esphome and home assistant. I have tried some things until the moment, the following is my last try… didn’t work well, just keeps toggling the output.
number:
- platform: template
id: coins
name: "Insert coins"
optimistic: true
min_value: 0
max_value: 10
step: 1
on_value:
then:
- repeat:
count: !lambda "return (int)x;"
# count: !lambda "return (int)id(coins).state;"
# count: 2
then:
- switch.turn_on: led
- switch.turn_on: pulse
- delay: 80ms
- switch.turn_off: led
- switch.turn_off: pulse
- delay: 80ms
I have tried using lambda, but the delay inside it makes the core reboot. If a count and repeat approach cannot be done, my last resort will be to create some buttons and use the on_press with pre-defined pulses.