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.