String versus Number in Blocky

Post Reply
DomoticaRob
Posts: 28
Joined: Sunday 29 November 2015 15:03
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Halle, the Netherland
Contact:

String versus Number in Blocky

Post by DomoticaRob » Monday 16 October 2017 22:51

I use a selector to input the desired temperature.
I have a temperature sensor connected to a ESP8266 that gives the temperature in the room.
I want to compare both to decide if the heater must switch on or off.
Can I covert a number to a string and/or can I convert a string to a number in Blocky?

Looking forward to a solution.

=======================================================================================================

The error code is:

2017-10-16 22:36:04.885 Error: EventSystem: Lua script error (Blockly), Name: Thermostaat_3 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: attempt to compare string with number



My Blocky is:
Blocky.png
Blocky.png (38.81 KiB) Viewed 303 times
My Selector is:
Selector_1.png
Selector_1.png (51.18 KiB) Viewed 303 times
Selector_2.png
Selector_2.png (187.21 KiB) Viewed 303 times

psb777
Posts: 5
Joined: Sunday 15 October 2017 14:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: String versus Number in Blocky

Post by psb777 » Tuesday 17 October 2017 1:13

You are comparing a temperature with "OFF". I don't think you can do that. But if that is valid then your report may be a duplicate of the issue I reported at http://www.domoticz.com/forum/viewtopic ... 8e58c96f92

I suggest you log the values you're comparing as I did in my Blocky code - then you can see what is going on.
The log will also show you which IF statement you're failing on.

I would be very interested in your findings.

DomoticaRob
Posts: 28
Joined: Sunday 29 November 2015 15:03
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Halle, the Netherland
Contact:

Re: String versus Number in Blocky

Post by DomoticaRob » Wednesday 18 October 2017 10:09

Thanks psb777 for your reply.

I use a selector switch in Domoticz because I want to input a desired temperature. The first level in a selctor switch is always ‘Off’. I can hide that level, so you don’t see it in your dashboard, but still the levels are strings.
The measured value is a number.
In lua you can convert a string to a number with the statement ‘tonumber’.

How do I compare in Blocky a selector switch value with a measured number value?

I had a solution, see Blocky example, but that is in my opinion a lazy programmers solution. In this case it can be ok, but in other situations I want a small solution.

Who can help me?

Blocky_2.png
Blocky_2.png (92.64 KiB) Viewed 264 times

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest