Simple IF - THEN not working

Moderator: leecollings

Post Reply
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Simple IF - THEN not working

Post by mvveelen »

Hi,

I have this in Lua:

Code: Select all

if aircoValueVaneZKval == "10" then 
commandArray['UpdateDevice'] = "739|0|50"
else
local aircoValueVaneZKval2 = aircoValueVaneZKval  * 10
commandArray['UpdateDevice'] = "739|0|" .. tostring(aircoValueVaneZKval2) .. "|"
end

The values can be:

aircoValueVaneZKval: 1 -> this has to be converted into 10, hence the * 10
aircoValueVaneZKval: 2 -> this has to be converted into 20, hence the * 10
aircoValueVaneZKval: 3 -> this has to be converted into 30, hence the * 10
aircoValueVaneZKval: 4 -> this has to be converted into 40, hence the * 10
aircoValueVaneZKval: 10 -> this has to be converted into 50......

So, where is the fault in my script?
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Simple IF - THEN not working

Post by jvdz »

try:

Code: Select all

local aircoValueVaneZKval2 = tonumber(aircoValueVaneZKval)
if aircoValueVaneZKval2 == 10 then 
	commandArray['UpdateDevice'] = "739|0|50"
else
	aircoValueVaneZKval2 = aircoValueVaneZKval2  * 10
	commandArray['UpdateDevice'] = "739|0|" .. tostring(aircoValueVaneZKval2) .. "|"
end
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Simple IF - THEN not working

Post by mvveelen »

Edit:

I forgot 2 lines of code. Your solution seems to work. Tomorrow I'll try to use it for the other values. Thanks!
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Simple IF - THEN not working

Post by mvveelen »

It's working with your code. I used it for all other values too and it works.

One thing: I had to split everything into separate Lua scripts (time). If I put all into one Lua script (time), only one value is updated. No problem though.

Now, every minute the status is updated. That's a lot, but I don't think it can do any harm to the Domoticz setup, right :D ?
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Simple IF - THEN not working

Post by jvdz »

That is easy to resolve too. :D
Just use this format for the commandarray entries:

Code: Select all

local aircoValueVaneZKval2 = tonumber(aircoValueVaneZKval)
if aircoValueVaneZKval2 == 10 then 
	commandArray[#commandArray + 1] = {['UpdateDevice'] = "739|0|50"}
else
	aircoValueVaneZKval2 = aircoValueVaneZKval2  * 10
	commandArray[#commandArray + 1] = {['UpdateDevice'] = "739|0|" .. tostring(aircoValueVaneZKval2)} 
end
Let me know when you need help converting the separate script by showing them and I'll help merging them.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
mvveelen
Posts: 697
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Simple IF - THEN not working

Post by mvveelen »

Ehm.....it's a lot.....but I copied them here: https://pastebin.com/76aSiXaU

Don't waste too much time, it works for now. And I don't want you to waste too much of your time. On the other hand: if it's easy to do: thanks in advance :-) !
RPi3b+/RFXCOM rfxtrx433E/Shelly/Xiaomi Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest