How to create a Blinking LED that I can command from Node-RED?

I have been able to create 3 “switched” LEDs that work just fine from Node-RED.

switch:
  - platform: gpio
    pin: GPIO6
    name: led_red

  - platform: gpio
    pin: GPIO8
    name: led_yellow

  - platform: gpio
    pin: GPIO10
    name: led_green

Now I want a Blinking LED…
So I have tried adding a light:

switch:
  - platform: gpio
    pin: GPIO40
    name: blink_red
    id: blink_red

light:
  - platform: monochromatic
    id: red_blink
    name: red_blink
    output: blink_red
    effects:
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%

But no-go! Apparently (I think), I can’t output to a switch?

ID 'blink_red' of type gpio::GPIOSwitch doesn't inherit from output::FloatOutput. Please double check your ID is pointing to the correct value.

Help…

Regards, Martin

Lots of issues, mainly that you’re combining lots of things that don’t go together.

Probably the easiest way to get what you’re after is to create a GPIO output:

Then create a binary light referencing that output:

And within that light, include the effect you want. Then you can simply turn on the light and set the effect.

1 Like

What I didn’t say in the OP, was that GPIO Output says:

Warning
This is an output component and will not be visible from the frontend. 

… and suggest that we use GPIO Switch. That is where the problem is, I can’t find a way for a Binary Light to output to a switch.

Did you read the docs for a binary light or what I wrote? You assign an output to it.

And yes, an output on its own doesn’t do anything or show up anywhere.

Yes, I have (for days!) and yes, I did. However, If I understand your advice, this is what I get:

output:
  - platform: gpio
    pin: GPIO40
    id: blink_red

light:
  - platform: binary
    name: "Blink" 
    output: blink_red
    effects:
      - pulse:
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s

… which gives:

The effect 'pulse' is not allowed for this light type.

Regards, M.

This is how I blink the built-in LED. Does this help?

# Blink the LED on D4 (GPIO2, LED_BUILTIN)
switch:
  - platform: gpio
    pin:
      number: D4 
      mode: output
    id: builtinLED

interval:
  - interval: 1000ms
    then:
      - switch.toggle: builtinLED

Yeah, as the error says, pulse isn’t supported for a binary light. Try strobe instead:

    effects:
      - strobe:
          name: Blink
          colors:
            - state: true
              duration: 500ms
            - state: false
              duration: 500ms

Thank you Steve,
But this blinks all the time. I am hoping for a blinking LED that I can turn on/off from the Dashboard UI (for testing but ultimately from Node-RED).

Regards, M.

Thanks Ben?
This is getting close. But… When I view the entity in Developer Tools, I note that there are 2 effects None and Strobe


So, now when I use the UI, this is what I see:
image
So, I think the question now is; What option do I add to the effects: so that there is only one effect and that is to Strobe when turned on? Or if there has to be minimum of two effects, reverse the order, so that Strobe is the default.

Regards, M.

Does this help?

# To control the enable and frequency variables, we create a template number
# and a template switch entry in our YAML. This will create two entities in
# Home Assistant where we can set the values.  
# The number.frequency is controlled using the set_value service.
#
number:
  - platform: template
    name: "Frequency"
    id: blink_frequency
    optimistic: true
    min_value: 0.1
    max_value: 100
    step: 0.1
    restore_value: true

switch:
  - platform: template
    name: "Enable"
    id: blink_enable
    optimistic: true
    restore_state: true


# When we create a CustomComponent we need to create a code file and register
# the Component in the config YAML. During the registration we can pass
# references to the switch and number inputs:
custom_component:
- lambda: |-
    auto myComponent = new AdvancedBlinkComponent(id(blink_enable), id(blink_frequency));
    return {myComponent};

I don’t believe there’s a way to remove the ‘none’ effect. However, you could make it switch to the strobe effect automatically every time it turns on using the on_turn_on trigger:

On mobile, so I can’t type up exactly what you’d need.

Edit: Decided to run down to my office to show you an example:

light:
  - platform: binary # or any other platform
    # ...
    on_turn_on:
    - light.turn_on:
        id: your_light_id
        effect: Strobe

Thank you Steve/Ben,

With your help, I have now got what I want. For others in the same (confused) state as I was, here is my solution. Firstly the ESPHOME code creatig the entities and driving the LEDs:

light:
  - platform: binary
    name: "Red" 
    output: blink_red
    effects:
      - strobe:
          colors:
            - state: true
              duration: 500ms
            - state: false
              duration: 500ms
 
output:
  - platform: gpio
    pin: GPIO6
    id: blink_red 

This produces a light with 2 modes - None (on steady) and Strobe. Now from Node-RED, I can create an action to Turn OFF, Turn ON (steady) & Turn ON (strobe) like this:

So, I’m outa here… Thanks.