Casambi and Domoticz

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Casambi and Domoticz

Post by erikjanverweij »

For my residential Lighting system, I switched to Casambi, a really Nice system based on Bluetooth low energy. A lot of design Lighting manifacturers in the world start to use this system for smart switching. Casambi does not have geofencing, thats why I want to hook it up to domoticz. Does Anyboddy know how to fix this? Www.casambi.com
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Casambi released a cloud API. https://casambi.com/wp-content/uploads/ ... online.pdf Does that mean I can finaly acces it via Domoticz? Is there someone who could help me make it work?
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi,
Casambi released a cloud API. https://casambi.com/wp-content/uploads/ ... online.pdf Does that mean I can finally access it via Domoticz? Is there someone who could help me make it work?
As there exist a cloud API, it would not be to difficult.
A Python library exists: https://github.com/hellqvio86/casambi and an MQTT interface: https://github.com/hellqvio86/casambimqttbridge

I discovered some activities in OpenHab and Home Assistant.

So I think there are possibilities with Node Red and Mosquitto (MQTT).

I suggest the following steps:

1. Arrange your API key, as presented in your PDF document.
2. Contact the API and see , what is returned.
Based on that you can decide if you use that API directly or use the Python script with MQTT
3. Use Node Red to collect the data, either directly from the Cloud API or by MQTT.
4. Create a NR flow and push it to Domoticz.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi FireWizard,

Thanx for your reply and help.

It took me some time, but I finally requested and arranged the API key.
Via the Casambi console I can contact the API and get the data.

Unfortunately i couldn't get the Python library installed. I got the following message.

pi@raspberrypi:~ $ pip install casambi
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting casambi
Could not find a version that satisfies the requirement casambi (from versions: )
No matching distribution found for casambi

do you know what's wrong?

Kind regards,
Erik-Jan
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi
@erikjanverweij

Obviously the python library casambi is not available in either https://pypi.org/simple, nor https://www.piwheels.org/simple.

The solution is to install it directly from github.

If you haven't git installed, install it as follows, otherwise skip this part.

Code: Select all

sudo apt-get update
sudo apt-get install git
Next install casambi from github:

Code: Select all

pip install git+https://github.com/hellqvio86/casambi.git#egg=casambi
Do the same with Casambi to MQTT bridge.

However it is interesting how the data in the Casambi console looks like.
Perhaps this python library is not necessary and is it possible to import this data in Node Red directly.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi FireWizard,

Tried to install the Casambi python library the way you told me, but still gives me an error:

pi@raspberrypi:~ $ pip install git+https://github.com/hellqvio86/casambi.git#egg=casambi
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting casambi from git+https://github.com/hellqvio86/casambi.git#egg=casambi
Cloning https://github.com/hellqvio86/casambi.git to /tmp/pip-install-yfE4_m/casambi
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-yfE4_m/casambi/setup.py", line 7, in <module>
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-yfE4_m/casambi/

I have never worked with Node Red before, but am looking into it.
The data in the Casambi console looks like this: https://developer.casambi.com/#rest-api
Looks like it works with javascript.

Kind regards,
Erik-Jan
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

@erikjanverweij

Hi,

As I have returned from a short break, I'm able to test it on my Raspberry Pi, instead of guessing that the theory will match with the practical results.

I was able to install Casambi with the command:

Code: Select all

pip3 install casambi
Can you try this?
You should see:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting casambi
Downloading https://files.pythonhosted.org/packages ... ne-any.whl
Collecting pyyaml (from casambi)
Downloading https://www.piwheels.org/simple/pyyaml/ ... armv6l.whl (44kB)
100% |████████████████████████████████| 51kB 409kB/s
Collecting websocket-client (from casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (200kB)
100% |████████████████████████████████| 204kB 213kB/s
Collecting requests (from casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (61kB)
100% |████████████████████████████████| 71kB 398kB/s
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from websocket-client->casambi) (1.12.0)
Collecting idna<3,>=2.5 (from requests->casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (58kB)
100% |████████████████████████████████| 61kB 372kB/s
Collecting chardet<4,>=3.0.2 (from requests->casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (133kB)
100% |████████████████████████████████| 143kB 162kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests->casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (126kB)
100% |████████████████████████████████| 133kB 322kB/s
Collecting certifi>=2017.4.17 (from requests->casambi)
Downloading https://files.pythonhosted.org/packages ... ne-any.whl (156kB)
100% |████████████████████████████████| 163kB 263kB/s
Installing collected packages: pyyaml, websocket-client, idna, chardet, urllib3, certifi, requests, casambi
The script chardetect is installed in '/home/pi/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed casambi-0.143 certifi-2020.6.20 chardet-3.0.4 idna-2.10 pyyaml-5.3.1 requests-2.24.0 urllib3-1.25.9 websocket-client-0.57.0
The next step is to install paho-mqtt:

Code: Select all

pip3 install paho-mqtt
You should see:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting paho-mqtt
Downloading https://www.piwheels.org/simple/paho-mq ... ne-any.whl (61kB)
100% |████████████████████████████████| 61kB 368kB/s
Installing collected packages: paho-mqtt
Successfully installed paho-mqtt-1.5.0
The next step is to install setproctitle:

Code: Select all

pip3 install setproctitle
You should see:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting setproctitle
Downloading https://www.piwheels.org/simple/setproc ... armv6l.whl
Installing collected packages: setproctitle
Successfully installed setproctitle-1.1.10
There might be small differences, as I installed it on a RPi1B

The next step is to install server.py from: https://github.com/hellqvio86/casambimqttbridge:

Code: Select all

git clone https://github.com/hellqvio86/casambimqttbridge.git
The directory casambimqttbridge is created in the directory, in which you executed the "git clone" command.
The contents is as follows:
-rwxr-xr-x 1 pi pi 1841 Jul 2 21:38 README.md
-rwxr-xr-x 1 pi pi 15457 Jul 2 21:38 server.py
The next steps are to install Mosquitto and Node Red, but let's try this first.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

@FireWizard

Thank you very much for your help! I think I have this part working now. The solution was to use pip3 instead of pip.
In the meantime I also have Node-Red running. I think I've got the connection to and from Domoticz via MQTT also already working.
I just have no idea how I get the MQTT messages from Casambi into Node-Red. Could you explain that to me?
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi,

@erikjanverweij

You said:
I think I've got the connection to and from Domoticz via MQTT also already working.
You can easily check this, by drag and drop a "MQTT output" (called MQTT in) node and a "Debug" node to the workbench and connect these together.

Screenshot_MQTT-debug.png
Screenshot_MQTT-debug.png (5.95 KiB) Viewed 2895 times
You have to configure the "MQTT In" node as follows:

Screenshot_VoC_12.png
Screenshot_VoC_12.png (18.58 KiB) Viewed 2895 times
You can give the MQTT Server any name (in this case RPi1_MQTT_Broker), you like.
The Name for the node is free to choose. The topic in this case is domoticz/out.

Next step is to click on the pencil behind the name in order to configure the MQTT server in Node Red.

Screenshot_IQ7-NodeRed-12.png
Screenshot_IQ7-NodeRed-12.png (28.53 KiB) Viewed 2895 times

Insert the IP address of your MQTT server. If it is installed on the same machine, it is localhost or 127.0.0.1, otherwise its IP address.
Leave the port default 1883.

Click on "Update", "Done" and finally "Deploy" in the upper right corner.

If everything is okay, you will see "connected" and messages from Domoticz are displayed in the debug pane.
For the moment you can leave the other tabs default, unless you have secured your MQTT server with a username/password.

Next step is to configure the casambi server.
Create a casambi.yaml configuration file, according to https://github.com/hellqvio86/casambimqttbridge (step 4)

Leave mqtt_user and mqtt_password empty, unless you have secured your MQTT server with a username/password.

Try to start the server.py (step 5)

If everything is alright messages will be published with topic casambi/light.

Make a similar setup as previous and insert a MQTT IN node with that topic. Check if you see anything in the debug pane.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @FireWizard

It all goes according to plan until I get to step 5. When I start the server.py like this:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/casambimqttbridge $ ./server.py
I get:
Process Casambi:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "./server.py", line 60, in casambi_worker
user_session_id = casambi.create_user_session(email=email, api_key=api_key, user_password=user_password)
AttributeError: module 'casambi' has no attribute 'create_user_session'
2020-07-04 20:24:29,584 7302 MQTT worker DEBUG mqtt_worker: Connecting to MQTT server 192.168.2.52:1883
2020-07-04 20:24:29,599 7302 MQTT worker DEBUG on_connect: Connected with result code 0
And no messages are published with topic casambi/light
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi,

@ erikjanverweij

As I remember, a message has been shown during the installation of casambi, that files has been installed in ~/.local/bin and that this directory was not in the PATH. So let's add this directory to the PATH variable first and try again.

Do as follows:

Code: Select all

PATH=$PATH:/home/pi/.local/bin
Check with:

Code: Select all

echo $PATH
Try to run the server again.

In order to make this path change persistent, add

Code: Select all

PATH=$PATH:/home/pi/.local/bin
as the last line to your .profile file in your home directory.

If you leave the terminal and return, this directory should be still in your path.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @FireWizard

When I type:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/casambimqttbridge $ PATH=$PATH:/home/pi/.local/bin
And then do:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/casambimqttbridge $ echo $PATH
I get:
/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/.local/bin:/home/pi/.local/bin
But running ./server.py gives me the same result as before:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/casambimqttbridge $ ./server.py
Process Casambi:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "./server.py", line 60, in casambi_worker
user_session_id = casambi.create_user_session(email=email, api_key=api_key, user_password=user_password)
AttributeError: module 'casambi' has no attribute 'create_user_session'
2020-07-06 20:24:15,728 2045 MQTT worker DEBUG mqtt_worker: Connecting to MQTT server 192.168.2.52:1883
2020-07-06 20:24:15,739 2045 MQTT worker DEBUG on_connect: Connected with result code 0
So I guess this does nog solve the problem, or am I missing something?

Kind regards, Erik-Jan
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi,

@erikjanverwey

It looks that the configuration file is not correct.
I assume you created it?
api_key: '...'
email: '[email protected]'
network_password: 'secret'
user_password: 'secret'
mqtt_server: '192.168.1.1'
mqtt_server_port: 1883
mqtt_user: 'casambi'
mqtt_password: '...'
In which directory did (if you did) you create this file?

I created the casambi.yaml file in the same directory as in which the ser.py has been installed.
It gives me the same error and of course I do not have a "api_key", correct email, a network password and a user password.
Can you check these once more.
The server did not connect with your casambi portal, but did connect with the MQTT server.
See:
2020-07-04 20:24:29,584 7302 MQTT worker DEBUG mqtt_worker: Connecting to MQTT server 192.168.2.52:1883
2020-07-04 20:24:29,599 7302 MQTT worker DEBUG on_connect: Connected with result code 0
I also discovered another issue.
./server.py: /usr/bin/python3^M: bad interpreter: No such file or directory
Obviously the file was edited/created with a Windows editor.
Have you been able to correct it?

Therefore various methods exist. A quick one is:

Code: Select all

sudo apt-get install dos2unix
followed by:

Code: Select all

dos2unix server.py
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @FireWizard,

I double checked everything but keep the same result.

In the meantime I have found another way to connect Casambi to Node-Red.
There is a Homebridge Casambi Plugin that works: https://github.com/awahlig/homebridge-casambi
And Homebridge can be linked to Node-Red again via: https://flows.nodered.org/node/node-red ... automation

So now I have managed to read and operate the Casambi Units in Node-Red and I can connect to Domoticz.

The only step I have to take now is to connect the two via script in Node-Red. Could you help me with that?
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

@erikjanverweij

Hi,
I double checked everything but keep the same result.

In the meantime I have found another way to connect Casambi to Node-Red.
There is a Homebridge Casambi Plugin that works: https://github.com/awahlig/homebridge-casambi
And Homebridge can be linked to Node-Red again via: https://flows.nodered.org/node/node-red ... automation
Okay, I was not aware of this plugin for Homebridge, as I do not use Apple.

But, if this works we abandon that plugin, as I have no opportunity to test that plugin.
The error message indicate that it cannot login, but it communicates with MQTT. Forget it.

I will delete all the Casambi stuff from my Raspberry Pi
So now I have managed to read and operate the Casambi Units in Node-Red and I can connect to Domoticz.

The only step I have to take now is to connect the two via script in Node-Red. Could you help me with that?
Can you show me what you get returned from Homebridge, preferable in a Node Red debug node?
If you want for private reasons, you may send a PM

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @FireWizard,

I have several nodes for input, output and status
Schermafbeelding 2020-07-09 om 11.37.55.png
Schermafbeelding 2020-07-09 om 11.37.55.png (116.23 KiB) Viewed 2782 times
When I toggle the light the input node gives me for example:
{"On":true,"Brightness":100}
or
{"On":false,"Brightness":0};
Tunable white lights also give ColorTemperature variable:
{"On":true,"Brightness":35,"ColorTemperature":440}
When I trigger with a timestamp, the status node gives me for example:
{"On":true,"Brightness":35,"ColorTemperature":440}
I can use the same msg.payload I receive to also toggle the lights from Node-Red

The thing I need to achieve is to take this data and change it to the right message so I can send it to the dummy light in Domoticz and vice versa. Hope you can help me with that.

Kind regards, Erik-Jan
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

@erikjanverweij
The thing I need to achieve is to take this data and change it to the right message so I can send it to the dummy light in Domoticz and vice versa. Hope you can help me with that.
I can, but I need one piece of information.

What are the minimum and maximum values for "ColorTemperature".
The value that you showed me is 440, but Domoticz needs values between 0 and 255. So we have to scale that.

To start with, you can create the number of virtual switches, you need.

For the first example create an ordinary virtual switch. Edit the switch and change the Switch Type to Dimmer.
For the second example create a RGBWW switch. Edit this switch and select the right (non colored) circle.

Screenshot_casambi1.png
Screenshot_casambi1.png (91.49 KiB) Viewed 2759 times

I have already created a flow from Homebridge to Domoticz.

Screenshot_casambi2.png
Screenshot_casambi2.png (16.87 KiB) Viewed 2759 times

In the Inject node I have used the same string as you showed me. You can replace the Inject node for the Homebridge node and this should work.
Replace in the Function node the IDX (currently 22) for your IDX number of the created virtual Dimmer.

The other flow is intended for Domoticz to Homebridge

In the switch node you have to change the IDX's for the IDX of you created virtual switches.
If needed you can expand this node

Of course you have to configure the Homebridge nodes with the correct pin and device name.

Screenshot_casambi3.png
Screenshot_casambi3.png (20.49 KiB) Viewed 2759 times

Find the flow below and test it.

Code: Select all

[{"id":"1bc01ca7.84b35b","type":"hb-event","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"ad94f0af.d9b61","x":170,"y":160,"wires":[[]]},{"id":"13ed1826.3acc98","type":"inject","z":"d5124b20.0bd73","name":"Dimmable Lamp","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"On\": false,\"Brightness\":0}","payloadType":"json","x":200,"y":220,"wires":[["dc14e084.45a228","35a3d452.9a70bc"]]},{"id":"5f7466a6.2b332","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":280,"wires":[]},{"id":"dc14e084.45a228","type":"function","z":"d5124b20.0bd73","name":"","func":"if (msg.payload.On === true)\n\n{\n    msg.payload = {\n        \"command\": \"switchlight\",\n        \"idx\": 22,\n        \"switchcmd\": \"Set Level\",\n        \"level\": msg.payload.Brightness\n        }\n}\n\nelse if (msg.payload.On  === false)\n\n{\n    msg.payload = {\n        \"command\": \"switchlight\",\n        \"idx\": 22,\n        \"switchcmd\": \"Set Level\",\n        \"level\": msg.payload.Brightness\n    };\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":220,"wires":[["5f7466a6.2b332","569d39cb.d79c68"]]},{"id":"569d39cb.d79c68","type":"mqtt out","z":"d5124b20.0bd73","name":"Domoticz In","topic":"domoticz/in","qos":"","retain":"","broker":"c2d9657a.d81bf8","x":590,"y":220,"wires":[]},{"id":"35a3d452.9a70bc","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":390,"y":280,"wires":[]},{"id":"764137d0.7ee2f","type":"mqtt in","z":"d5124b20.0bd73","name":"Domoticz Out","topic":"domoticz/out","qos":"2","datatype":"json","broker":"c2d9657a.d81bf8","x":130,"y":380,"wires":[["c218839c.7b098"]]},{"id":"9167765.52c4f08","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":440,"wires":[]},{"id":"c218839c.7b098","type":"switch","z":"d5124b20.0bd73","name":"Filter Idx","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"22","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":380,"wires":[["c4df2cec.242588"],["8f58d3f0.d86c"]]},{"id":"8f58d3f0.d86c","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":440,"wires":[]},{"id":"c4df2cec.242588","type":"function","z":"d5124b20.0bd73","name":"","func":"switch (msg.payload.nvalue) {\n    \n    case 0: //Uit\n    msg.payload = {\"On\":false,\"Brightness\":0};\n    break;\n\n    case 1: //Aan\n    msg.payload = {\"On\":true,\"Brightness\":parseInt(msg.payload.svalue1)};\n    break;\n\n    case 2: //Dimmer stand\n    msg.payload = {\"On\":true,\"Brightness\":parseInt(msg.payload.svalue1)};\n    break;\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":360,"wires":[["9167765.52c4f08","b01aad6.2c131d"]]},{"id":"b01aad6.2c131d","type":"hb-control","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"361f342f.410a7c","x":740,"y":360,"wires":[]},{"id":"ad94f0af.d9b61","type":"hb-conf","z":"","username":"12345"},{"id":"c2d9657a.d81bf8","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"361f342f.410a7c","type":"hb-conf","z":"","username":"12345"}]

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @Firewizard

You're the best! Works like a charm! :D

There is one thing that does not work. When I switch a light off in Casambi, the light in Domoticz does not turn off. It only happens with off. Switching a light to on or change dim value works from Casambi to Domoticz. What could that be?

I also checked the maximum and minimum values for ColorTemperature. Maximum is 222 (4500K) and minimum is 454 (2200K).

Kind regards, Erik-Jan
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Casambi and Domoticz

Post by FireWizard »

Hi,

@erikjanverweij

Thank you, but we are not finished yet.
There is one thing that does not work. When I switch a light off in Casambi, the light in Domoticz does not turn off. It only happens with off. Switching a light to on or change dim value works from Casambi to Domoticz. What could that be?
Sometimes a program contains a bug and unfortunately, the flow I sent too :(
But it should be solved now. Test it.
I also checked the maximum and minimum values for ColorTemperature. Maximum is 222 (4500K) and minimum is 454 (2200K).
This means that Casambi, via Homebridge, has a range from CoolWhite (222) to WarmWhite (454) of 232 steps.
As Domoticz uses from 0-255 I have stretched the range, if the data is going from Casambi to Domoticz a little and squeezed it, when it goes from Domoticz to Casambi.

You will find the complete flow below, but it is somewhat modified, compared with the previous one.

Screenshot_casambi4.png
Screenshot_casambi4.png (73.97 KiB) Viewed 2718 times

I will explain a little.

The top flow is for Casambi to Domoticz, only for dimmable lights, while the flow in the middle has the extra possibility for the color temperature.
There is no flow for color (RGB) lamps. If you need that, it has to be made.
The bottom flow is for Domoticz to Casambi

I made the flows somewhat universal.
As I understand you can connect only one device to the Homebridge node, called Choose accessory/service"
In the change node, called "Set topic" I have set the IDX number (in Domoticz) as topic.
So you can connect multiple "Dimmable lamp + Set topic" combinations to the Function node.
So you have to modify the change node and set your own Domoticz IDX.
Of course you might have to modify the MQTT nodes.

For the dimmable lamp = color temperature, it is exactly the same

For the flow, used from Domoticz, you have to set the IDX in the switch node, called "Filter Idx".
You can expand the switch node to, as many lamps as you have.
You have to copy the "Function" and "Homebridge" node, but be carefully that you copy the right combination for your lamp.
The top is for dimmable lights only, while the bottom has the color temperature option.

If it is to your satisfaction, you can remove all debug (green) nodes and the 2 inject (grey) nodes.

Below, you will find the flow.

Code: Select all

[{"id":"1bc01ca7.84b35b","type":"hb-event","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"ad94f0af.d9b61","x":210,"y":100,"wires":[["1e59e9f8.5e134e"]]},{"id":"13ed1826.3acc98","type":"inject","z":"d5124b20.0bd73","name":"Dimmable Lamp","props":[{"p":"payload"},{"p":"topic","v":"22","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"On\":true,\"Brightness\":70}","payloadType":"json","x":240,"y":160,"wires":[["dc14e084.45a228","35a3d452.9a70bc"]]},{"id":"5f7466a6.2b332","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":220,"wires":[]},{"id":"dc14e084.45a228","type":"function","z":"d5124b20.0bd73","name":"","func":"if (msg.payload.On === true)\n\n{\n    msg.payload = {\n        \"command\": \"switchlight\",\n        \"idx\": msg.topic,\n        \"switchcmd\": \"Set Level\",\n        \"level\": msg.payload.Brightness\n        }\n}\n\nelse if (msg.payload.On  === false)\n\n{\n    msg.payload = {\n        \"command\": \"switchlight\",\n        \"idx\": msg.topic,\n        \"switchcmd\": \"Off\",\n        };\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":160,"wires":[["5f7466a6.2b332","569d39cb.d79c68"]]},{"id":"4b0c5fb4.e0158","type":"function","z":"d5124b20.0bd73","name":"","func":"if (msg.payload.On === true)\n{\n    msg.payload = {\n        \"command\": \"setcolbrightnessvalue\",\n        \"idx\": msg.topic,\n        \"brightness\": msg.payload.Brightness,\n        \"color\": {\n            \"m\": 2,\n            \"t\": parseInt((msg.payload.ColorTemperature -222) * (255/232))\n        }\n    }\n}       \nelse if (msg.payload.On  === false)\n{\n    msg.payload = {\n        \"command\": \"switchlight\",\n        \"idx\": msg.topic,\n        \"switchcmd\": \"Off\"\n    };\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":340,"wires":[["40e4b0fb.b1c758","1caf3621.faef12"]]},{"id":"569d39cb.d79c68","type":"mqtt out","z":"d5124b20.0bd73","name":"Domoticz In","topic":"domoticz/in","qos":"","retain":"","broker":"c2d9657a.d81bf8","x":630,"y":160,"wires":[]},{"id":"35a3d452.9a70bc","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":220,"wires":[]},{"id":"f7cae54f.ce536","type":"inject","z":"d5124b20.0bd73","name":"Dimmable Lamp +Temp","props":[{"p":"payload"},{"p":"topic","v":"23","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"On\":true,\"Brightness\":50,\"ColorTemperature\":454}","payloadType":"json","x":220,"y":340,"wires":[["368e6d35.53640a","4b0c5fb4.e0158"]]},{"id":"368e6d35.53640a","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":400,"wires":[]},{"id":"40e4b0fb.b1c758","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":400,"wires":[]},{"id":"1caf3621.faef12","type":"mqtt out","z":"d5124b20.0bd73","name":"Domoticz In","topic":"domoticz/in","qos":"","retain":"","broker":"c2d9657a.d81bf8","x":630,"y":340,"wires":[]},{"id":"764137d0.7ee2f","type":"mqtt in","z":"d5124b20.0bd73","name":"Domoticz Out","topic":"domoticz/out","qos":"2","datatype":"json","broker":"c2d9657a.d81bf8","x":130,"y":562,"wires":[["c218839c.7b098"]]},{"id":"9167765.52c4f08","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":482,"wires":[]},{"id":"c218839c.7b098","type":"switch","z":"d5124b20.0bd73","name":"Filter Idx","property":"payload.idx","propertyType":"msg","rules":[{"t":"eq","v":"22","vt":"str"},{"t":"eq","v":"23","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":562,"wires":[["c4df2cec.242588"],["c639dbd.b51c8a8","34360a5e.048fde"]]},{"id":"c4df2cec.242588","type":"function","z":"d5124b20.0bd73","name":"","func":"switch (msg.payload.nvalue) {\n    \n    case 0: //Uit\n    msg.payload = {\"On\":false,\"Brightness\":0};\n    break;\n\n    case 1: //Aan\n    case 2: //Dimmer stand\n    msg.payload = {\"On\":true,\"Brightness\":parseInt(msg.payload.svalue1)};\n    break;\n\n    \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":522,"wires":[["9167765.52c4f08","b01aad6.2c131d"]]},{"id":"b01aad6.2c131d","type":"hb-control","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"361f342f.410a7c","x":730,"y":522,"wires":[]},{"id":"52348e9f.df7248","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":662,"wires":[]},{"id":"34360a5e.048fde","type":"debug","z":"d5124b20.0bd73","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":662,"wires":[]},{"id":"c639dbd.b51c8a8","type":"function","z":"d5124b20.0bd73","name":"","func":"switch (msg.payload.nvalue) {\n    \n    case 0: //Uit\n    msg.payload = {\"On\":false,\"Brightness\":0};\n    break;\n    \n    case 1: //Aan\n    case 10: //Color Temperature\n    case 15: //Dimmer stand\n    msg.payload = {\"On\":true,\"Brightness\":parseInt(msg.payload.svalue1),\"ColorTemperature\":parseInt((msg.payload.Color.t) * (232/255) + 222)};\n    break;\n\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":500,"y":602,"wires":[["52348e9f.df7248","c5dd41b3.9f6b28"]]},{"id":"c5dd41b3.9f6b28","type":"hb-control","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"361f342f.410a7c","x":730,"y":602,"wires":[]},{"id":"22f1313.67945ce","type":"hb-event","z":"d5124b20.0bd73","name":"","Homebridge":"","Manufacturer":"","Service":"","device":"","conf":"ad94f0af.d9b61","x":210,"y":280,"wires":[["3de8f322.a34b6c"]]},{"id":"1e59e9f8.5e134e","type":"change","z":"d5124b20.0bd73","name":"Set topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"22","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":100,"wires":[["dc14e084.45a228"]]},{"id":"3de8f322.a34b6c","type":"change","z":"d5124b20.0bd73","name":"Set topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"23","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":280,"wires":[["4b0c5fb4.e0158"]]},{"id":"ad94f0af.d9b61","type":"hb-conf","z":"","username":"12345"},{"id":"c2d9657a.d81bf8","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"verifyservercert":true,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"361f342f.410a7c","type":"hb-conf","z":"","username":"12345"}]
Awaiting your test result.

Regards
erikjanverweij
Posts: 17
Joined: Thursday 06 October 2016 12:36
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Woerden (NL)
Contact:

Re: Casambi and Domoticz

Post by erikjanverweij »

Hi @FireWizard,

I only have it working for a short while, but it looks like it's working flawles.
Thanks again for your help! Otherwise I really couldn't have done it ...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest