Page 2 of 2

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 15:07
by Thuis
Is that a question to me? on github ?

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 15:09
by waltervl
No just an extra remark and confirmation to the developers that it is not working anymore as before.

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 15:23
by Thuis
Ah ok, thanks for backing it up !

Re: X10 Dimmers; A simple solution

Posted: Thursday 23 February 2023 16:07
by Thuis
Well i have tested the new script from github, and it works. But it gives an error in the log.

Code: Select all

EventSystem: in script_device_dimmers:[string "commandArray = {}..."]:22: bad argument #1 to 'pairs' (table expected, got nil)
Status: User: admin (IP: xxx.xxx.xxx.xxx) initiated a switch command (172/Lamp Aanrecht/Set Level)
Status: LUA: idx: 172, name: Lamp Aanrecht, state: On, svalue: 30, nvalue: 2
Status: LUA: /home/onshuis/Domotica/domoticz/scripts/lua/mochad_dim.sh J3 18 
I see the light dim and brighten and go on and off so it all works, but the error.

I have no clue what it means. But the script seems to work!
Do you know perhaps a solution to the bad argument?

Re: X10 Dimmers; A simple solution

Posted: Thursday 23 February 2023 16:18
by Thuis
Ok i put

Code: Select all

if (devicechanged_ext ~= nil) then
in front of line 22, and the error is gone.
So thanks all is working now :-)

So to update the forum post, the changed script from Gizmocuz on github is this:

Code: Select all

commandArray = {}

local BASHSCRIPT = "/home/pi/domoticz/scripts/lua/mochad_dim.sh "  --keep the space at the end!

local bashcall = ""
dimmers = {}

-- Dimmer names must be strictly identical to the dimmer labels
dimmers["Lumiere Salon"]="o4"
dimmers["Lumiere Salle a Manger"]="o6"
dimmers["Lumiere Chambre 1"]="o8"
dimmers["TestDimmer"]="o10"
dimmers["TestSwitch"]="o11"
dimmers["Lumiere Bureau"]="o12"
dimmers["Lumiere Chambre 3"]="o13"

if (devicechanged_ext ~= nil) then
for name,value in pairs(devicechanged_ext) do
	if (name == "name") then
		local X10Address=dimmers[value]
		--If a registered Dimmer
		if X10Address ~= nil then
			-- Create appropriate way to call the BASH script
			local state = devicechanged_ext["state"];
			local level = tonumber(devicechanged_ext["svalue"]);

			print ("idx: "..devicechanged_ext["idx"]..", name: "..devicechanged_ext["name"]..", state: "..state..", svalue: "..tostring(level)..", nvalue: "..devicechanged_ext["nvalue"]);

			if state == "Off" then
				bashcall=BASHSCRIPT ..X10Address.." ".. "Off"
			elseif state == "On" then
				if (level == 0) then
					bashcall=BASHSCRIPT ..X10Address.." ".. "On"
				else
					local intdata=(tostring(math.floor(level*0.63)))
					bashcall=BASHSCRIPT..X10Address.." "..intdata    	    
				end
			end
			--Call the Bash script
			--os.execute(bashcall)		        
			print(bashcall);
		end
	end
end
end
return commandArray
And is working as a tierelier. Thanks to gizmocuz and waltervl for helping me.

Re: X10 Dimmers; A simple solution

Posted: Thursday 23 February 2023 17:16
by waltervl
To be clear, to use this new script you have to update domoticz to the latest beta version 15095 or higher.

Re: X10 Dimmers; A simple solution

Posted: Thursday 23 February 2023 17:17
by Thuis
waltervl wrote: Thursday 23 February 2023 17:16 To be clear, to use this new script you have to update domoticz to the latest beta version 15095 or higher.
Yes thanks, it was clear.

Re: X10 Dimmers; A simple solution

Posted: Thursday 23 February 2023 17:23
by waltervl
Thuis wrote: Thursday 23 February 2023 17:17
waltervl wrote: Thursday 23 February 2023 17:16 To be clear, to use this new script you have to update domoticz to the latest beta version 15095 or higher.
Yes thanks, it was clear.
To you probably it was clear but not for the other users that will have the same problem and read this thread :-)

Re: X10 Dimmers; A simple solution

Posted: Friday 24 February 2023 11:20
by Thuis
You are right again :D