Page 1 of 2

X10 Dimmers; A simple solution

Posted: Friday 20 January 2017 14:20
by Persisto
Domoticz does not support X10 dimmers, various solutions have been proposed, none of which I found easy to implement.

Mochad, the X10 interface used by Domoticz, supports dimming like so:

Code: Select all

echo pl A1 xdim 63  | nc localhost 1099
the value must be 1-63 (other values are accepted but have different effects; 64 will dim to 0 over a period of a minute etc.)
(I have Marmitek LW11 dimmers and this works fine)

I wrote 2 simple scripts which based on values from a dummy dimmer, send instructions directly to Mochad.

Unfortunately, based on what Mochad reports to have done (and done well) DOmoticz will report an error (in the log) which can be ignored

Code: Select all

Error: Mochad: Cannot decode 'Tx PL HouseUnit: O13 Func: Ext code 1, data, control Data: 00 Command: 31'
This is how it works;
LUA script: Identify the dimmer which changed, find corresponding X10Address, identify "On", "Off" or "Slider position Changed" send appropriate values to a BASH script. (Save as /home/pi/domoticz/scripts/lua/script_device_dimmers.lua on a raspberry)

Code: Select all

commandArray = {}

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

local X10Address
local bashcall
local intdata
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["Lumiere Chambre 2"]="o10"
dimmers["Lumiere Entree"]="o11"
dimmers["Lumiere Bureau"]="o12"
dimmers["Lumiere Chambre 3"]="o13"


for deviceName,deviceValue in pairs(devicechanged) do
	--Find the X10 Address 
	X10Address=dimmers[deviceName]
	--If a registered Dimmer
	if X10Address ~= nil then
		-- Create appropriate way to call the BASH script
		--print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
		if deviceValue == "On" then
			bashcall=BASHSCRIPT ..X10Address.." ".. "On"
       		elseif deviceValue == "Off" then
			bashcall=BASHSCRIPT ..X10Address.." ".. "Off"
		else
			intdata=(tostring(math.floor(tonumber(string.sub(deviceValue,-5,-2))*0.63)))

			bashcall=BASHSCRIPT..X10Address.." "..intdata
		end
		--Call the Bash script
		os.execute(bashcall)
	end
end

return commandArray
and the Bash script (saved as /home/pi/domoticz/scripts/lua/mochad_dim.sh)

Code: Select all

if [ "$2" = Off ];then
echo pl $1 off  | nc localhost 1099

elif [ "$2" = On ];then
echo pl $1 on  | nc localhost 1099

else
echo pl $1 xdim $2  | nc localhost 1099
fi


All-tough this works, it is a hack, it would be nice if X10 dimmers would be supported directly!
(Liberate the slider on the png, send " xdim & int(slidervalue *.63) to the dimmer when it changes ...and a lot of X10 users would be happy!)

PS:
As I found it tricky to find how to create dummy dimmers (this is not done as you would expect):
To create a Dummy Dimmer
1) In Hardware Create Dummy Hardware
2) Create a Dummy switch by clicking on Create Virtual Sensors n the Hardware page. (And not on the Switches Page! Your slider will not work!)
Choose Switch as Sensor type.
3) On the Switches page edit the just created switch and set the type to Dimmer

Re: X10 Dimmers; A simple solution

Posted: Saturday 21 January 2017 11:15
by franzelare
Thanks for sharing!

If I read your script correct, you can only send dimmer values from domoticz and not read the status of 2 way dimmers if the dim level is changed manually?

I solved this by adding a CM11 next to my CM15, just to read the status of the 2 way X10 dimmers I have.
see here: viewtopic.php?f=56&t=11949

Re: X10 Dimmers; A simple solution

Posted: Saturday 21 January 2017 12:25
by Persisto
Hello,

Thanks for reacting.

I had read your solution, but did not want to add Heyu+CM11 to my system and did not feel up to the dealing with the complexity of your scripts (My posted scripts were the first I ever made)

I am not sure my dimmes can be "read" (Marmitek LW11) what is the brand/model of yours?
I can live with a dimmer that dims to say 50% of max when I tell it to, (rather than 25% less than "actual", regarless of how it got to "actual")
This is particulalry so, since setting from my phone is easier and faster than pressing a "certain time" on the flimsy paddles of the LW11

I am curious to know how you actually manage to get the xdim instruction out to the dimmmers, Domoticz does not pass anythng but "on" or "off" to Mochad as far as I can see. (But maybe I do not see well and it is your Heyu part that takes care.)

Re: X10 Dimmers; A simple solution

Posted: Saturday 21 January 2017 12:44
by franzelare
LW11 is not possible to read through the X10 interface, I only check if they are on with a optocoupler conencted to a mysensor node that is located there anyway...
I use LW12 for one way dimmers and LWM1p/DAIX12 dimmers for 2 way dimmers

See my link for the scripts I use to send and read the dim values using the CM11 and track on off in domoticz using the CM15Pro.
basically the dimmer on my frontpage is a virtual switch, i have a virtual switch to track if the device is operated manually and a switch in the CM15Pro hardware to pass on/off through mochad
I do agree it is some what complex and it took me a while before I go the scripts up and running correctly and can control the dimmers through domoticz using a customize frontpage.

Re: X10 Dimmers; A simple solution

Posted: Saturday 27 May 2017 10:11
by dommedomgebr
As a wheelchair user I totally rely on remote controls. After my 2nd Marmitek Easy Touch 35 recently died I decided to invest in a Pi based solution to control my LM12W X10 dimmers and my klik-aan-klik-uit type RF dimmers and switches using my Android mobile phone. Having read that both systems used by me are supported by Domoticz,I installed Domoticz on a new Pi 3 with a new CM15Pro, only to discover that my dimmers are not supported by Domoticz! I am rather disappointed, to say the least :-(

I realise that the LM12W dimmers are 1-way but do not understand why that is a problem. Mochad can send dim commands, so why can't Domoticz?

What surprises me about the argument is that when Domoticz uses the LM12W as a switch it is also 1-way. Domoticz cannot read the on/off status either but this does not mean it cannot use the LM12W as a switch. Would not the same be true for a dimmer?

Is there any chance that Domoticz will have X10/Mochad dimmer support in the near future?

Re: X10 Dimmers; A simple solution

Posted: Saturday 27 May 2017 14:09
by franzelare
dommedomgebr wrote:As a wheelchair user I totally rely on remote controls. After my 2nd Marmitek Easy Touch 35 recently died I decided to invest in a Pi based solution to control my LM12W X10 dimmers and my klik-aan-klik-uit type RF dimmers and switches using my Android mobile phone. Having read that both systems used by me are supported by Domoticz,I installed Domoticz on a new Pi 3 with a new CM15Pro, only to discover that my dimmers are not supported by Domoticz! I am rather disappointed, to say the least :-(

I realise that the LM12W dimmers are 1-way but do not understand why that is a problem. Mochad can send dim commands, so why can't Domoticz?

What surprises me about the argument is that when Domoticz uses the LM12W as a switch it is also 1-way. Domoticz cannot read the on/off status either but this does not mean it cannot use the LM12W as a switch. Would not the same be true for a dimmer?

Is there any chance that Domoticz will have X10/Mochad dimmer support in the near future?
you can mannualy add the switches with the correct housecode and use at least the on / off function with the CM15pro
to use the dimmer function you indeed have to do a bit of lua scripting, but codes for that are available on the forum

Re: X10 Dimmers; A simple solution

Posted: Saturday 27 May 2017 18:35
by dommedomgebr
Hi Franzelare,

I don“t have a CM11. Will it work without one?

Re: X10 Dimmers; A simple solution

Posted: Sunday 28 May 2017 16:40
by franzelare
cm15 i did not try to get this working
cm11 second hand is widely available for very little money

Re: X10 Dimmers; A simple solution

Posted: Tuesday 13 June 2017 14:06
by Persisto
I have a CM15Pro and the scripts I published in the first post of this thread work on LW12W in the way you require/propose: The current status is ignored, the instruction (via a dummy on DOmoticz interface) to dim to X% will make the LW12W dim to X% regardless of its previous status.

Re: X10 Dimmers; A simple solution

Posted: Friday 06 April 2018 12:55
by Persisto
After a "segmentation fault" and a complete re-install (with new versions of Linux and Domoticz) the LUA script did not work (LUA script running for more than 10 seconds: The LUA script now seems to wait for the end of the BASH script.)

Modifying the BASH script by adding a 0 seconds time-out as below solved the problem.

Code: Select all

if [ "$2" = Off ];then
echo pl $1 off  | nc localhost 1099 -w 0

elif [ "$2" = On ];then
echo pl $1 on  | nc localhost 1099 -w 0

else
echo pl $1 xdim $2  | nc localhost 1099 -w 0
fi

Re: X10 Dimmers; A simple solution

Posted: Tuesday 21 February 2023 15:03
by Thuis
I know this is a bit of an old thread, but i have a problem which seems i can not solve by myself.

I have been using this script for several years and it works great, but as of the latest beta, it stopped working, only on or off works, the dimming has stopped. Now i need to change the script so it is working again, but i can not work out, how to change the script with this:

Code: Select all

return {
	on = {
		devices = {
			'Test Switch'
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
	},
	execute = function(domoticz, device)
	    local mydimmer = domoticz.devices(8343)
	    
        if device.state == 'On' then
            domoticz.log('Device ' .. device.name .. ' is ON! Level:' .. device.level, domoticz.LOG_INFO)
            mydimmer.setLevel(65)
        else 
            domoticz.log('Device ' .. device.name .. ' is OFF!', domoticz.LOG_INFO)
            mydimmer.switchOff()
        end	    
	end
}
So it works again, every time when i try to change something i get errors like: bad argument #1 to 'pairs' (table expected, got nil)

I there someone willing to help me out, so i can use the script for my X10 dimmers, and get the latest beta>?

Thanks in advance.

Re: X10 Dimmers; A simple solution

Posted: Tuesday 21 February 2023 17:25
by waltervl
So it seems the bash script is not running correctly or the calculation fails. Do you see errors coming out of the lua script?

What happens if you call the bashcript manually with an fake dimming value?

What happens if you set it manually with for example (change to your own values)

Code: Select all

echo pl A1 xdim 63  | nc localhost 1099

Re: X10 Dimmers; A simple solution

Posted: Tuesday 21 February 2023 18:36
by Thuis
Hey thanks for answering. Why it works for 5 years now. Im at Version: 2022.2 (build 14992).
When i update to Version 2023.1.15092 the dimming stops only on off works.

When i do this

Code: Select all

echo pl J3 xdim 10  | nc localhost 1099
or this

Code: Select all

echo pl J3 xdim 63  | nc localhost 1099
the dimming just works.

There are no errors in the log.

Im not sure i understand what to do next.

I revert back to 14992 then i dim to 50% the light goes to 50% and this is in log:
LUA: Device based event fired on 'Lamp Aanrecht', value 'Set Level: 50 %'

i put the light to 80% and the light goes to 80%. then

I revert to 15092 then i dim to 50% the light goes on, to 80% (last value) this is in log:
LUA: Device based event fired on 'Lamp Aanrecht', value 'On'

So yes, i need to stick with 14992, because i have no clue why or how????

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 0:34
by waltervl
Yes, then my Lua knowledge stops as it seems that DeviceValue does not contain the setlevel value anymore.
Perhaps a Lua programmer can step in....

But are you using exactly the same Lua script and the bash script as indicated in this topic (besides other device names off course)?

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 0:51
by waltervl
I tested it in latest beta and there I get indeed no setlevel value back in Lua when changing the dimmer level from the Domoticz user interface (device is already switched on).

Code: Select all

Status: User: admin (IP: 192.168.x.xx) initiated a switch command (81/light test/Set Level)
Status: LUA: Lua test Device based event fired on 'light test', value 'On'
I used this lua line to print the log:

Code: Select all

print ("Lua test Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
What do you get with this log line in your script in version 14992?

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 10:50
by Thuis
Yes it is the same script i am using.
When i add this line i get this under the line, that is already there:

Status: LUA: Device based event fired on 'Lamp Aanrecht', value 'Set Level: 23 %'
Status: LUA: Lua test Device based event fired on 'Lamp Aanrecht', value 'Set Level: 23 %'

this is in version 14992. Im trying to change the script, but everything i do results in errors.
I also hope, some one can help to change it, so i can keep using my x10 devices and use latest beta.

And now with 15092 i get this:
Status: LUA: Device based event fired on 'Lamp Aanrecht', value 'On'
Status: LUA: Lua test Device based event fired on 'Lamp Aanrecht', value 'On'

It says 'On' but its actually at 23%.

Yes i figured something like that too, I get indeed no setlevel value back. But i have no clue how to change it, so it will work again.

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 11:24
by waltervl
This seems to be a bug then.
Do you also see in old domoticz the administrator setlevel action? For example:
User: admin (IP: 192.168.x.xx) initiated a switch command (81/light test/Set Level)

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 11:32
by Thuis
Yes i do see that:

Status: User: admin (IP: xxx.xxx.xxx.xxx) initiated a switch command (172/Lamp Aanrecht/Set Level)
Status: LUA: Device based event fired on 'Lamp Aanrecht', value 'Set Level: 50 %'

A bug, i dont know, i tried to ask at github but there was not the place to ask this, i had to use the forum, so that is why i am here now.
At github someone else had the same thing: https://github.com/domoticz/domoticz/issues/5610
And i think that i am misunderstood, because i do not mean any harm, but im unable to formulate probably what there is wrong.
So im very happy, you see the same behaviour as i do.

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 11:38
by waltervl
That issue is about something else that is why it was rejected.
Please make a new issue with the script and also the log result in old Domoticz and new.
Also refer to this topic.

Re: X10 Dimmers; A simple solution

Posted: Wednesday 22 February 2023 11:40
by Thuis
Well its a bit scary to do, but i will give it another go then.

Its done