ESPHome and NodeMCU with local logic

I’m trying to re-use some NodeMCU devices I programmed through the Arduino programming interface that I’ve been using since before implementing HASS. These have a PIR and a microwave sensor and do the following:

  • while neither PIR or microwave sensor is triggered, it flashes an LED at 1Hz
  • if either the PIR or microwave is triggered it flashes the LED at 2Hz
  • if both are triggered simultaneously it turns the LED solid on and then sends a webhook to BlueIris
  • solid LED resets after 30 seconds

I’ve got the NodeMCU working with Hass and ESPHome (to replace the webhook) but have no idea how to programme the NodeMCU to run the local logic (flashing the LED, monitoring for the PIR and microwave etc) while running under ESPHomeAPI.

Essentially, what I’m struggling with is how do I make it run the local logic as well as be an input for HASS?

Thanks.

Richard

I found how to flash the LED

switch:
  - platform: gpio
    pin: D5
    name: "LED01"
    id: led01
       
interval:
  - interval: 1sec
    then:
      - switch.toggle: led01

So I’m getting closer but it sends a status update for each of these events - can updates for routine events like this be suppressed?

Yes, set the logger level to:

logger:
  level: WARN

Thank you, Tom!

That stops it logging the switching but it still transmits the state to the HASS. For this purpose I don’t need the state of the LED sent to HASS (and so the switch in HASS moves on and off with the LED) - is there a way to disable it?

You could try using a GPIO output instead of a switch: