I want compare get where it's a day time or night time. I'm getting sunrise and sunset time from the weather API. I don't how to compare the data using switch node.
Format the sunrise and sunset times to UTC (milliseconds since 1 January 1970) then get the current time (JavaScript Date getTime() Method) and use a switch
node or function
node to do the comparison
msg.data, msg.sunrise and msg.sunset was getting correct but whenever i run this it giving otherwise output only
You will have two msgs entering the comparing node BUT they will not arrive at the same time. You would need to use a join
node before the 'Comparing' node to get them to arrive at the same time.
If you move the 'Set msg.data right after the 'Weather data' node, you could have the current time in the same msg as the sunrise or sunset time.
I'm getting output but the thing is, I used combining output as string is there any other option to get output instead of using string
The join node is not what you want here.
Put all nodes in series and all properties into individual propertys (e.g. inject msg.now = timestamp
, msg.sunrise = msg.payload.xxxx, msg.sunset = msg.payload.yyyy `
then your compare can do between msg.sunset and msg.sunrise
etc.
If you are simply trying to figure out what point of the day it is, then I recommend node-red-contrib-cron-plus...
Demo flow...
[{"id":"a6d46dff.aca4d","type":"inject","z":"c876e57260edd2ab","name":"describe solar","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"command\":\"describe\",\"location\":\"35.45743499930747 139.63778346776962\",\"expressionType\":\"solar\",\"solarType\":\"selected\",\"solarEvents\":\"sunrise,sunset\",\"timeZone\":\"Europe/London\",\"offset\":60,\"info\":\"Get sunrise/sunset times and status at yokohama intercontinental (35.45743499930747 139.63778346776962)\"}]","payloadType":"json","x":730,"y":1660,"wires":[["4eb68abd.a39914"]]},{"id":"4eb68abd.a39914","type":"cronplus","z":"c876e57260edd2ab","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","defaultLocation":"","defaultLocationType":"default","outputs":2,"options":[],"x":1020,"y":1660,"wires":[[],["2d35c203.e28a0e"]]},{"id":"2d35c203.e28a0e","type":"debug","z":"c876e57260edd2ab","name":"Command result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1220,"y":1660,"wires":[]},{"id":"c4fd78d7.203dd8","type":"comment","z":"c876e57260edd2ab","name":"Simple demo of using the describe command to get solar state","info":"","x":860,"y":1620,"wires":[]},{"id":"a5ef21003ae53641","type":"cronplus","z":"c876e57260edd2ab","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output2","defaultLocation":"","defaultLocationType":"default","outputs":2,"options":[{"name":"ukne","topic":"uk/ne/solar_events","payloadType":"default","payload":"","expressionType":"solar","expression":"0 * * * * * *","location":"54.9990878447323 -1.4176440238952634","offset":"0","solarType":"selected","solarEvents":"sunrise,sunset"}],"x":960,"y":1780,"wires":[[],["3e7e072d1929f45d"]]},{"id":"3e7e072d1929f45d","type":"debug","z":"c876e57260edd2ab","name":"Command result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1220,"y":1780,"wires":[]},{"id":"fe54c07f1471b999","type":"comment","z":"c876e57260edd2ab","name":"Simple demo asking for status of a fixed solar schedule","info":"","x":840,"y":1740,"wires":[]},{"id":"f1c6f23ee6f27315","type":"inject","z":"c876e57260edd2ab","name":"status of ukne","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"status","payload":"ukne","payloadType":"str","x":730,"y":1780,"wires":[["a5ef21003ae53641"]]}]
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.