Home Assistant and WLED Presets

Hi!

I didn’t find it in official docs from HA site is there any way to call WLED preset (1-16) from HA? I see that this option (preset:) is listed in entity options but I can’t set or configure it.

Or this option is not yet fully integrated to HA?

I know that I can switch presets with rest command and HTTP API and right now I’m already using it but I want to try HA scenes in automation and it would be great that preset and playlist options would be available in HA integration. :slight_smile:

Thanks!

This is currently not yet available in the native API implementation in Home Assistant. But should become available in a future update (on the Home Assistant plug-in side), no time-frame is known at the point in time.

Thank you for information! :slight_smile:

To piggyback off this, say I have a preset that I like, and want to convert it into a hassio automation. Is there a convenient way to view/export the values stored in the preset?

Hi! To get the preset contents for using the JSON API, load the preset, navigate your browser to http://[WLED-IP]/json/state and then let the automation set that string (you can also remove properties from the JSON that are not part of the preset but that is not strictly required)

3 Likes

@Aircoookie Can you clarify this technique?

I have the string

{"on":true,"bri":255,"transition":7,"ps":16,"pss":12319,"pl":-1,"ccnf":{"min":1,"max":5,"time":12},"nl":{"on":false,"dur":60,"fade":true,"tbri":0},"udpn":{"send":false,"recv":true},"lor":0,"mainseg":0,"seg":[{"id":0,"start":0,"stop":91,"len":91,"grp":1,"spc":0,"on":true,"bri":255,"col":[[255,0,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":true,"rev":false},{"id":1,"start":91,"stop":181,"len":90,"grp":1,"spc":0,"on":true,"bri":255,"col":[[8,255,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":false,"rev":false}]}

Are you saying to send this as a POST to the JSON API via HomeAssistant through the REST mechanism (which I’m already using with HTTP API) or something different that I’m not seeing. For the HomeAssistant integration, there are the six fields listed at the bottom on the ref doc.

Thank you for this wonderful project!

Hi, I’m very glad that you like WLED :slight_smile:

Yes, exactly that! Just send the string as a POST to /json/state (though all the properties between bri and seg are not needed, you can remove them and arrive at

{"on":true,"bri":255,"seg":[{"id":0,"start":0,"stop":91,"len":91,"grp":1,"spc":0,"on":true,"bri":255,"col":[[255,0,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":true,"rev":false},{"id":1,"start":91,"stop":181,"len":90,"grp":1,"spc":0,"on":true,"bri":255,"col":[[8,255,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":false,"rev":false}]}

)

1 Like

Thank you!

Your support is nothing short of incredible. You clearly love this project as much as I love using it.

I’ve used the HTTP API for a long time, and am now discovering just how powerful the JSON API is. This allows me to fairly easily replicate across disparate nodes (diff length, segments, etc). I have had problems with sync in the past, usually due to wonky connectivity.

And if anyone is wondering how to remove segments, it’s in the JSON API doc - just make the STOP # be lower than the START # or set both to zero.

1 Like

Hello
First: very nice Work @Aircoookie
I like to do the same, but i have no experience with HTTP API. I tried this with out luck:

rest_command:
  wled_sofa:
    url: http://192.168.178.121/json/state
    method: POST
    payload: '{"on":true,"bri":20,"seg":[{"id":0,"start":0,"stop":91,"len":91,"grp":1,"spc":0,"on":true,"bri":20,"col":[[255,0,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":true,"rev":false},{"id":1,"start":91,"stop":181,"len":90,"grp":1,"spc":0,"on":true,"bri":20,"col":[[8,255,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":false,"rev":false}]}'

and under autmation.yaml:

- alias: 'wled_sofa_special'
  trigger:
    platform: blabla
  action:
    - service: rest_command.wled_sofa
      data:
        url: http://192.168.178.121/json/state
        method: POST
        payload: '{"on":true,"bri":20,"seg":[{"id":0,"start":0,"stop":91,"len":91,"grp":1,"spc":0,"on":true,"bri":20,"col":[[255,0,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":true,"rev":false},{"id":1,"start":91,"stop":181,"len":90,"grp":1,"spc":0,"on":true,"bri":20,"col":[[8,255,0],[0,0,0],[0,0,255]],"fx":58,"sx":154,"ix":84,"pal":2,"sel":false,"rev":false}]}'

When I start the automation, it works. But the home-assistant wled-integration dosn’t work any more (all light changes go back after 1 sec.).
Can somebody help me?
Thanks!

Create CURL commands from your payload data. Send them manually using CURL. If they behave correctly - meaning they do not revert back to previous values after 1 second, then WLED is not to blame. It is either the integration, or how your system is using it.

Hi @YvesIF I don’t know if this will help you or if you’re still trying to get this to work but I have a flow in node red that works with the preset commands. It uses @Aircoookie above advice posting the string.

First you will need to set the payload message as the string you’ll get from the raw data on the `[WLEDIP]/json/state’ page. Then change the payload to a post and use a HTTP request node set the method to POST in the url box put http://[WLEDIP]/json/state/{{post}} finally return a parsed JSON object.

I hope this helps in some way thank you @Aircoookie for all your amazing work!

Can you post a copy of the nodered flow? Thanks.

Thank you very much I will check it out shortly.

Two issues I have found; first node-red-contrib-wled has zero documentation - are there some examples of programming it? I’m hoping it works better than node-red-contrib-wled2 which only seems to work with two or maybe three instances. After that it shows them as “connecting”. I’m assuming it isn’t meant to run in discrete instances. I’m trying to have a normal schedule of evening on, midnight off. But I want to override that with special days. I was going to use Bigtimer to schedule the events but I need a separate ON and I can only really get an ON and an OFF to both be online. I’m probably going to need to go to MQTT for this.

Edit: I managed to do the same thing in BigTimer through MQTT so I can have as many events as I like without having to bog down the wemos.

I found the easiest way to do it in NodeRED is to use use the JSON Api and using the HTTP POST method. I also tried node-red-contrib-wled2 but found the JSON API worked better in my experience.

I had seen that you can just post to it that way, too. I’m super happy with mqtt through bigtimer. If you already have mqtt running it makes sense.

I’d like to add something since I’m not seeing it anywhere else. Doing this doesn’t require any custom cards. Just vanilla HA, HA helpers, HA automations and official wled integration.

You can use the state of an input select helper or input select integration (in config.yaml) then add helper to a card in lovelace to easily change the effect. Helpers can be used via automations on all wled attribute states that are available with service calls. Also input select helper state can be set from wled attribute state when effect is changed by some other means such as changing a preset or changing the effect in wled web ui. Again this can be done for all wled attributes exposed in home assistant.

Here are my automations for controlling wled. I made a separate one for each but I’m sure this could be done more elegantly.

alias: Set Effect
description: ''
trigger:
  - platform: state
    entity_id: input_select.effect
condition: []
action:
  - service: wled.effect
    data:
      effect: '{{ states("input_select.effect") }}'
    entity_id: light.wled
mode: single

alias: Set effect to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: effect
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "effect") }}'
    entity_id: input_select.effect
mode: single
alias: Set Intensity
description: ''
trigger:
  - platform: state
    entity_id: input_number.intensity
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      intensity: '{{ states("input_number.intensity") }}'
    entity_id: light.wled
mode: single
max: 10

alias: Set intensity to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: intensity
condition: []
action:
  - service: input_number.set_value
    entity_id: input_number.intensity
    data:
      value: '{{ state_attr("light.wled", "intensity") }}'
mode: single
alias: Set palette
description: ''
trigger:
  - platform: state
    entity_id: input_select.palette_list
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      palette: '{{ states("input_select.palette_list") }}'
    entity_id: light.wled
mode: single
alias: Set palette to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: palette
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "palette") }}'
    entity_id: input_select.palette_list
mode: single
alias: Set Preset
description: ''
trigger:
  - platform: state
    entity_id: input_select.preset
    for: '00:00:00'
condition: []
action:
  - service: wled.preset
    data:
      preset: '{{ states("input_select.preset") }}'
    entity_id: light.wled
mode: single
alias: Set preset to dropdown
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: preset
condition: []
action:
  - service: input_select.select_option
    data:
      option: '{{ state_attr("light.wled", "preset") }}'
    entity_id: input_select.preset
mode: single
alias: Set Reverse
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.reverse
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      reverse: '{{ states("input_boolean.reverse") }}'
    entity_id: light.wled
mode: single
alias: Set Speed
description: ''
trigger:
  - platform: state
    entity_id: input_number.speed
    for: '00:00:00'
condition: []
action:
  - service: wled.effect
    data:
      speed: '{{ states("input_number.speed") }}'
    entity_id: light.wled
mode: single
alias: Set speed to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
    attribute: speed
condition: []
action:
  - service: input_number.set_value
    data:
      value: '{{ state_attr("light.wled", "speed") }}'
    entity_id: input_number.speed
mode: single
alias: Set Brightness
description: ''
trigger:
  - platform: state
    entity_id: input_number.brightness
condition: []
action:
  - service: light.turn_on
    data:
      brightness: '{{ states("input_number.brightness") }}'
    entity_id: light.wled
mode: single
alias: Set brightness to slider
description: ''
trigger:
  - platform: state
    entity_id: light.wled
condition: []
action:
  - service: input_number.set_value
    data:
      value: '{{ state_attr("light.wled", "brightness") }}'
    entity_id: input_number.brightness
mode: single
1 Like

Capture-7