Yes, but no need to parse any thing, you use the id code to do the lookup. 50 plus codes, will give you the option of 50+ day icons and 50+ night icons.
I also notice that your inject node seems to inject the table.
That isn't how the openweathermap
node works. It sends the message with the current weather. Not a table of associated numbers and icons.
You know exactly what it does and know in your mind how it works.
To me it is magic. As in smoke and mirrors.
I'm not dismissing it, but what I am seeing doesn't fit to what I want to do.
You inject a big table to be indexed by the function
node.
I need a variable incoming message to be indexed to convert what is in the message to an icon.
I'm not seeing that.
I see you sending me a table (which doesn't exist in my world) and so it all falls apart there.
Yes thats because i did not want to store it to context or save it as a file, and to make a quick simple example i put the table in the inject node.
I could have had the table in context and just do a look up on it with the id.
in my example the injected msg payload is the id form the openweather map json, the injected table would be on your node-red.
Well, I can't see any ....... way that will work for me.
I have explained why, and what I see. Remember: I am not you. I can't see what you see.
Interestingly you mentioned "storing in a file". Yikes! that is something else I want to do with something else!
That would be great to also get a handle on. but not now! I want to get this problem fixed as practically as possible.
Then move to the next problem. And believe me: That is a F*ing big bucket! (sorry)
I need to build a small table to "lookup/index" a name to a number.
(The other problem)
I need to store values in a file and read the values in and use then as needed.
Editing nodes and changing variables is painful. Not that they will be often edited. Just for now they are a bit dynamic as I tweak things to get values correct.
Once I have the magic numbers they will be written back to nodes.
But those are other problems. For now I want to get this better controlled. At least hog tied so it doesn't run away and go feral on me.
Then I can look at the other problems.
Steve, I have made progress in what you gave me and it is looking good.
Alas I had to add two more lines for the rain variable, but that's my problem and I did it.
I'll play with it as is for a while.
I still need to learn how to apply it to the real flow. That comes later.
For now I want to grow this to the next stage.
There needs to be a night/day conversion for some/most icons.
If it is overcast (I'll get to that shortly) then the day/night icons don't have the sun/moon in them.
The overcast is determined by the cloud cover part of the message.
I'll pick a value and if the value is above that, the generic style icons will be shown. Otherwise the day/night ones.
I'll see if I can nut that out in your style. But last night/yesterday I spent about 10 hours on it and have made a lot of progress doing it the hard way.
Probably all to be thrown away when I get your code better understood.
Basically I was doing what yours does, but the longer/harder way with a lot of switch
nodes.
It got messy quickly.
ok, maybe you can see this example better.
I have put openweathermap return json in the inject, and given you an inject to store the table to context.
All you need to do is add a night icon to the table and a time conditional to pick night or day icon. A full lookup object is available on the links i have posted above.
[{"id":"f1645547.d9b598","type":"inject","z":"8d22ae29.7df6d","name":"press once to store context icon data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"200\":{\"label\":\"thunderstorm with light rain\",\"icon\":\"storm-showers\"},\"201\":{\"label\":\"thunderstorm with rain\",\"icon\":\"storm-showers\"},\"202\":{\"label\":\"thunderstorm with heavy rain\",\"icon\":\"storm-showers\"},\"210\":{\"label\":\"light thunderstorm\",\"icon\":\"storm-showers\"},\"211\":{\"label\":\"thunderstorm\",\"icon\":\"thunderstorm\"},\"212\":{\"label\":\"heavy thunderstorm\",\"icon\":\"thunderstorm\"},\"221\":{\"label\":\"ragged thunderstorm\",\"icon\":\"thunderstorm\"},\"230\":{\"label\":\"thunderstorm with light drizzle\",\"icon\":\"storm-showers\"},\"231\":{\"label\":\"thunderstorm with drizzle\",\"icon\":\"storm-showers\"},\"232\":{\"label\":\"thunderstorm with heavy drizzle\",\"icon\":\"storm-showers\"},\"300\":{\"label\":\"light intensity drizzle\",\"icon\":\"sprinkle\"},\"301\":{\"label\":\"drizzle\",\"icon\":\"sprinkle\"},\"302\":{\"label\":\"heavy intensity drizzle\",\"icon\":\"sprinkle\"},\"310\":{\"label\":\"light intensity drizzle rain\",\"icon\":\"sprinkle\"},\"311\":{\"label\":\"drizzle rain\",\"icon\":\"sprinkle\"},\"312\":{\"label\":\"heavy intensity drizzle rain\",\"icon\":\"sprinkle\"},\"313\":{\"label\":\"shower rain and drizzle\",\"icon\":\"sprinkle\"},\"314\":{\"label\":\"heavy shower rain and drizzle\",\"icon\":\"sprinkle\"}}","payloadType":"json","x":310,"y":2280,"wires":[["5d1e3139.825f6"]]},{"id":"5d1e3139.825f6","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"icons","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":2280,"wires":[[]]},{"id":"1ac7ba4.2e908c6","type":"inject","z":"8d22ae29.7df6d","name":"230 id from json","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":230,\"weather\":\"Clouds\",\"detail\":\"overcast clouds\",\"icon\":\"04n\",\"tempk\":288.87,\"tempc\":15.7,\"temp_maxc\":16.1,\"temp_minc\":15.5,\"humidity\":90,\"pressure\":1005,\"maxtemp\":289.26,\"mintemp\":288.71,\"windspeed\":4.47,\"winddirection\":206,\"location\":\"Eastbourne\",\"sunrise\":1604213458,\"sunset\":1604248430,\"clouds\":99,\"description\":\"The weather in Eastbourne at coordinates: 50.77, 0.28 is Clouds (overcast clouds).\"}","payloadType":"json","x":140,"y":2360,"wires":[["97554150.eea59"]]},{"id":"d0a181cb.20af","type":"inject","z":"8d22ae29.7df6d","name":"312 id from json","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":312,\"weather\":\"Clouds\",\"detail\":\"overcast clouds\",\"icon\":\"04n\",\"tempk\":288.87,\"tempc\":15.7,\"temp_maxc\":16.1,\"temp_minc\":15.5,\"humidity\":90,\"pressure\":1005,\"maxtemp\":289.26,\"mintemp\":288.71,\"windspeed\":4.47,\"winddirection\":206,\"location\":\"Eastbourne\",\"sunrise\":1604213458,\"sunset\":1604248430,\"clouds\":99,\"description\":\"The weather in Eastbourne at coordinates: 50.77, 0.28 is Clouds (overcast clouds).\"}","payloadType":"json","x":140,"y":2400,"wires":[["97554150.eea59"]]},{"id":"97554150.eea59","type":"function","z":"8d22ae29.7df6d","name":"A simple table lookup","func":"msg.payload = flow.get(\"icons\")[msg.payload.id];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":2360,"wires":[["c6154d5c.e76c58"]]},{"id":"c6154d5c.e76c58","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":2360,"wires":[]}]
That code I wrote for you took me 15 minutes.
We knew it would be - That is why early on I said a black box approach would be better.
Yeah, but you are smarter than me!
And I agree. That is why I am doing it as a sub-flow - ultimately. If it does happen.
But getting my head around it..... Ouch!
I need to expand your code to allow for day/night/overcast things.
Then there is a whole part of CLEAR SKY. Winds... etc.
I'm having a bit of trouble with that because.... I am.
With the code I wrote in each "sub section" I set the icon and only changed it if needed.
This cut back on a lot of work.
Where as your way I have to fill every "hole" and in mine I didn't. The trade off is I guess how it all fits together.
Just back on the black box idea.
Yeah, as I said, I get it. But for me: the writer, I can't have a black box other than at the operational level.
I have to know how it works all the same. But I guess you were talking in the general level, and not the specifics of how it works.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.