How to report pulse width of laser only when triggered?

Hi all,

Been scratching my head with this one for a while, and it’s time to ask for help.

Put simply, I’ve got an ESP8266 with a laser receiver board connected, and I’ve got the pulse width sensor component reading it in ESPHome and reporting to HA fine.

The problem is: I have a custom flat laser beam remote that has two different PWM’s (10ms and 50ms, both with 50% duty cycle) and I want ESPhome to report what the PWM of the laser beam that just passed over it was. At the moment, if the 10ms laser passes over the sensor, the ESPHome node waits until the interval time (up to 60s at the moment) and then tells HA that value. AND it reports that exact same value every 60s for the rest of time.

I would like this node to only send the pulse width of the last laser beam it saw, and only report instantly after it happens. So if I shine the 10ms pulse at it, it tells HA it saw the 10ms pulse, and if 10 minutes later I shine the same 10ms pulse at it, it does the same thing again. And if 30 minutes later I shine the 50ms pulse at it, it reports it just saw the 50ms pulse.

Here’s the very basic code I’ve got so far:

  - platform: pulse_width
    pin: D1
    name: Pulse Width Sensor

Anyone even got any hints? Should I be looking down the manual local automation route for example?

Don’t bump your post so quickly. Have patience and wait 24 hours.

Take a good look at these options

What do you want the sensor to read between readings, or when it gets a repeat pulse?

Can you use the pulse counter to tell when there was a detectable pulse on the time interval and then create a template sensor that does what you want?

Sorry for being impatient. Being in the UK on Covid lockdown is a bit boring.

I would like the sensor to tell HA instantly the pulse width of the laser beam that just passed over it, and then HA when no laser beam has passed over it.

Imagine this sensor as two separate momentary push button switches. When the 10ms laser passes over the switch, one output is triggered. when the 50ms laser passes over it, the other switch triggers. And also, these output needs to be momentary, which is what I’m struggling with. At the moment if the 50ms laser passes over the sensor, the sensor tells HA every 60s seconds about that same event. It doesn’t reset to “no pulse detected in the last 5 seconds” for example.

I spent a fair while looking through those already, but can’t see how any could achieve my goal.

I can’t see a way for that to be able to differentiate between the 10ms and 50ms pulses.

Use it to detect an actual signal then use the pulse width sensor to tell which signal it was. I’m not sure if you can be sure these sensors will have the same update schedule however.

If only the one pulse is detected, is it possible to have both the pulse width and pulse counter sensor work on the same singular pulse?

I don’t think so, it seems like this should be a feature request for esphome as it doesn’t seem easy to do otherwise.

In that case it seems like the logical approach would be to just use the pulse width sensor, but work out how to have it only report that pulse width instantly, and only only once. Surely that’s possible?