# "Truth tables" and how to build them - help required

**URL:** https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142
**Category:** General
**Created:** [1 November 2020 03:06 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142 "2020-11-01T03:06:40Z")
**Posts on this page:** 10
**Page:** 2

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 November 2020 21:04 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/21 "2020-11-01T21:04:23Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 November 2020 21:10 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/22 "2020-11-01T21:10:52Z")

</div>

All the codes are from 200 to 999, no letters all unique.

 ![Screenshot_20201101-211310](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d926dab7631f528d045e3d9cdddf31886ad9cd0.png)

The id property not the ico property

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [1 November 2020 21:14 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/23 "2020-11-01T21:14:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 November 2020 21:16 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/24 "2020-11-01T21:16:58Z")

</div>

> [@Trying\_to\_learn](#):
>
> I also notice that your inject node seems to inject the table.

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.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [1 November 2020 21:22 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/25 "2020-11-01T21:22:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [1 November 2020 21:29 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/26 "2020-11-01T21:29:27Z")

</div>

@Steve-Mcl

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.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [1 November 2020 21:40 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/27 "2020-11-01T21:40:09Z")

</div>

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.

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [1 November 2020 21:42 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/28 "2020-11-01T21:42:02Z")

</div>

> [@Trying\_to\_learn](#):
>
> I spent about 10 hours on it and have made a lot of progress doing it the hard way

That code I wrote for you took me 15 minutes.

> [@Trying\_to\_learn](#):
>
> It got messy quickly.

We knew it would be - That is why early on I said a black box approach would be better.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [1 November 2020 21:57 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/29 "2020-11-01T21:57:49Z")

</div>

> [@Steve-Mcl](#):
>
> That code I wrote for you took me 15 minutes.

Yeah, but you are smarter than me! 😉

> [@Steve-Mcl](#):
>
> We knew it would be - That is why early on I said a black box approach would be better.

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [31 December 2020 21:57 UTC](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142/30 "2020-12-31T21:57:52Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/truth-tables-and-how-to-build-them-help-required/35142.md?page=1)
