First of all, Happy New Year! I thought I’d start this year with an attempt at being more active again here on my blog. So this is it. :)

I was trying to control my Synology DS212 directly through my CCU2 such that I could power it on and off by pressing a button on a wall-mounted Homematic IP six-way switch.

CUx-Daemon prooves to be the swiss-army knife when it comes to these things in the Homematic universe. Configuring the virtual switch was a bit tricky, though, so I will briefly explain how to do it here. I will not go into the details of installing CUxd, though.

As for configuration, I ended up creating a new Switch through the CUxd interface, e.g. http://homematic-ccu2/addons/cuxd/index.ccc?m=4.

CUxd Settings

It’s a system switch, type exec and use a virtual switch, set to switch mode - this allows me to trigger actions and capture state with a single virtual device.

CUxd Device

I then configured the device to only have one channel and report as unreachable if any of the commands returns any error.

CUxd Device General Parameters

Now comes the tricky bit - the actual channel settings.

CUxd Device Channel 1 Parameters

CMD_SHORT is executed when the switch is turned off. It essentially logs into the diskstation and executes poweroff. This requires root access, hence the need to echo the admin password to sudo.

/usr/bin/ssh -o 'StrictHostKeyChecking no' -o 'UserKnownHostsFile /dev/null' -i /etc/ssh_host_rsa_key admin@diskstation 'echo XXXXXXXX | sudo -S poweroff'

CMD_LONG is executed when the switch is turned on. This simply uses ether-wake, obviosuly you want to provide to correct MAC.

/usr/local/addons/cuxd/extra/ether-wake 00:11:XX:XX:XX:XX

Set timeout for execution of each of these to one minute.


Run the command in CMD_TIMER every 15 seconds.


This one took me a while to figure out. For some reason the webui does not like a couple of characters to be put into the input boxes. Specifically the equal sign (=) leads to the field being empty or partial. I was able to work around this by url-encoding the http call to set the switch state - maybe there is a more elegant solution, but this works.

To still explain a bit more, when the switch is set to on/off via the web interface that sets the state, but that state has nothing to do with the actual state of the diskstation. So I use ping to check if it is up. Then I call SET_STATE of the virtual button (CUX2801003) with the (inverted) result of that ping command. SET_STATE modifies the button state without triggering a switch action, i.e. by doing SET_STATE to on that does not execute ether-wake but just modified button state.

! ping -q -c 1 diskstation; wget -q -O /dev/null http://homematic-ccu2:8181/cuxd.exe?x%3Ddom.GetObject%28%22CUxD.CUX2801003%3A1.SET_STATE%22%29.State%28$?%29

That, in short, summarizes what I did. It does work quite well now and I am happy with it.

Leave a comment