Create a schedule in node red

Im new to Node-Red and Im lost before I start. I would like to convert my yaml automations to NR.

I want to create a flow to turn on and off the radio based on presence and change to different stations depending on the time and day.

So a typical scenario would be:

Radio on station 1 from 6:00 - 23:30 everyday

  • Between 20:00 and 23:30 everyday change station to say station 2
  • On a Friday afternoon between 13:00 - 15:00 change to station 3
  • On a Saturday between 12:00 -14:00 change to station 4
  • on Sunday between 9:00 - 18:00 change to station 5

Outside these times default back to station 1 or 2 depending on time and presence.

I have this sort of working in yaml in loads of separate automations that are hard to understand especially when I go back to them and try and understand what I did and why I did it.

Some advice on how to schedule this would help a lot.

I’m using this node in Node-Red https://github.com/niklaswall/node-red-contrib-light-scheduler
Maybe that covers your needs as well.

1 Like

That is pretty straight forward. You can use time range nodes or if you want it all in one, there is a node called big timer. Simply connect your trigger to the “time checking nodes” as a kind of condition and from the output you simply call the corresponding service.

If you can share your current flow that doesn’t work as expected we can take a look :slight_smile:

1 Like

I haven’t done anything yet, I wasn’t sure how to start. I had a look at the light scheduler and thought I can assign each radio station to its own light schedule and possibly work from that.

Im learning as I go.

That should work too :slight_smile: I can simply encourage you to just give it a go, and when you run into an issue, simply post your flow and somebody will help you fix it

I am getting an error when trying to call a service in NR.
The flow im testing is this:

[{"id":"2e2838f1.008318","type":"tab","label":"Music","disabled":false,"info":""},{"id":"e6842b5b.08c26","type":"api-call-service","z":"2e2838f1.008318","name":"Radio LBC","server":"73b9d82e.6dc188","version":1,"debugenabled":true,"service_domain":"squeezebox","service":"call_method","entityId":"media_player.portable_radio","data":"command: playlistparameters:  - play  - Radio_Lbc","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":130,"y":160,"wires":[["224f35a.ce87eca"]]},{"id":"76afe814.5e00c8","type":"inject","z":"2e2838f1.008318","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":60,"wires":[["e6842b5b.08c26"]]},{"id":"224f35a.ce87eca","type":"debug","z":"2e2838f1.008318","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":110,"y":260,"wires":[]},{"id":"73b9d82e.6dc188","type":"server","z":"","name":"Home Assistant","addon":true}]

If I enter this into Dev.tools - services using squeezebox.call_method the service works

entity_id: media_player.portable_radio
command: "playlist"
parameters:
  - play
  - Radio_Lbc

But pasting this into a service call node and manually triggering it with a inject timestamp retunes

15/07/2020, 22:37:17node: Radio LBC
msg :
{ domain: "squeezebox", service: "call_method", data: object }
15/07/2020, 22:37:17node: Radio LBC
msg : string[74]
"Call-service API error.  Error Message: extra keys not allowed @ data['0']"

Any ideas please.

Your DATA is put in yaml. You need to put this as JSON in NodeRed.

{"command":"playlist","parameters":["play","Radio_Lbc"]}

https://www.convertjson.com/yaml-to-json.htm

1 Like

Ah, great, thanks for the link too