Volumio Connector for Domoticz

Python and python framework

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Volumio Connector for Domoticz

Post by emme »

Ciao,

I finally found my way to connecto Volumio2 to my Domoticz
Iwas thinking to create a plugin, but I'm not so skilled, so I choose a Python servicewhich connect via socketIO and keep Domoticz updated, while Domoticz can control Volumio using the http REST API
...if.. for any reason... someone would like toconvert it into a plugin it would be really appreciated!!

here is how it works:
Unfortunately it works only unde linux
in domoticz you need to create 3 dummy devices:

SWITCH DIMMER that will act as volume and mute/unmute
SWITCH SELECTOR that will act as basic controls (PLAY/STOP/PREV/NEXT)
TEXT DEVICEthat will act as a display
Create those 3 and keep note of their IDX

Device Configuration (edit them)
SWITCH DIMMER
  • Name: Volumio Volume (you can use whatever you want, but we will is it later)
  • Switch Type: Dimmer
  • Icon: Speaker
  • Save
SWITCH SELECTOR
  • Name: Volumio Volume (you can use whatever you want, but we will is it later)
  • Switch Type: Selector
  • Icon: Amplifier
  • Level 0 Name: off (cannot change)
  • Level 10 Name:◄◄
  • Level 20 Name: ►
  • Level 30 Name: ►►
  • Level 0 Action : http://<volumio_IP>/api/v1/commands/?cmd=stop
  • Level 10 Action: http://<volumio_IP>/api/v1/commands/?cmd=prev
  • Level 20 Action: http://<volumio_IP>/api/v1/commands/?cmd=play
  • Level 30 Action: http://<volumio_IP>/api/v1/commands/?cmd=next
  • Save
other levels can be used to access playlist... if so the level action to call a playlist will be
http://<volumio_IP>/api/v1/commands/?cmd=playplaylist&name=<playlist Name>

The TEXT DEVICE does not need any special configuration except its name

now you need to create a dzVents Script in which you can copy/paste the following:

Code: Select all

return {
   active = true,
   on = { devices = {'Volumio Volume'} },-- NUse the same name as setted in the Volume device 
   execute = function(dz, devVol)
      local volumio = '<volumio_IP>'
      if devVol.state == 'Off' then
         os.execute('curl "http://'..volumio ..'/api/v1/commands/?cmd=volume&volume=mute"')
      else
         os.execute('curl "http://'..volumio ..'/api/v1/commands/?cmd=volume&volume='..devVol.level..'"')
      end
   end
}
save it and be sure to enable it...
now save the attached file in a folder into your linux system

Connect in Telnet/SSH to your linux system
be sure you have SocketIO installed by issuing

Code: Select all

sudo pip3 install SocketIO-client
move to the folder where you placed the file and edit it to fill the needed information:

Code: Select all

VOLUIP = '<Volumio_IP>'

DEVIDX    = '000'  # VOLUME CONTROL
DEVTXT    = '000'  # DISPLAY CONTROL
DEVCTL    = '000'  # DEVICE CONTROL
save the file
now let's create the service (these instruction works under Raspberry, other systems may need an adjustment:

Code: Select all

sudo nano /lib/systemd/system/dzVol.service
copy and paste the following code:

Code: Select all

[Unit]
Description=Volumio connector for Domoticz
After=multi-user.target

[Service]
User=root
Type=idle
ExecStart= /home/pi/utility/dzVol.py

[Install]
WantedBy=multi-user.target
enter the full path where the file is at line ExecStart (in my case is /home/pi/utility/dzVol.py) save it as dzVol.service (press CTRL-X and enter the file name)
now some other command to complete the installation:

Code: Select all

sudo chmod +x /home/pi/utility/dzVol.py
sudo chmod +x /lib/systemd/system/dzVol.service
sudo systectl daemon-reload
sudo systemctl enable dzVol.service
sudo systemctl start dzVol.service
sudo systemctl status dzVol.service
you should see the service in active (running) mode

...that's all... you should be now able to change volume and use command on both domoticz and volumio UI to have the other side updated
hope you enjoy it
let me know what you think about it :P
ciao
M
Attachments
dzVol.py.txt
Remove .txt extension
(3.75 KiB) Downloaded 247 times
Last edited by emme on Thursday 25 January 2018 15:23, edited 1 time in total.
The most dangerous phrase in any language is:
"We always done this way"
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Volumio Connector for Domoticz

Post by EdwinK »

looks great, I think. Now if only someone would make such a nice thing for Max2Play
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
jppmedia
Posts: 1
Joined: Sunday 25 March 2018 22:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Volumio Connector for Domoticz

Post by jppmedia »

Hello,
It's really a very good idea! I am not familiar with the code, script, etc .... So if a passionate Volumio and music, was kind, nice to make a plugin, it will be really fanstastic! There must be a great person on this forum!
Thank you very much.
jp
(I'm French, this is translated with google, I know but nobody is perfect!)
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Volumio Connector for Domoticz

Post by emme »

after few month in whitch I tested the connector I would start moving to something else.

The service experienced hangs, disconnections and a wired loop while changing volume...

So.. I start interesting in MQTT, and NodeRed and I found a way by which the service is much more stable with less scripting, and use the MPD server on volumio instead of socketIO.

The result is that it works like a charm with no script at all!!!.
So...
trow away the python, lua/dzVents script and use MQTT and Node-Red instead.
User MPD control to gather info in realtime and MQTT do send/receive Domoticz command
The presents (playlist and play controls) will run as HTTP actions while the Volume slider will be used by the MQTT interface.

I'll update the nodered flow soon (mine uses a dashboard UI also.... so I would like to duplicate it in a clean way)

MQTT is a REALLY good solution and widely open to almost everything!!!
ciao
M
The most dangerous phrase in any language is:
"We always done this way"
Ries
Posts: 40
Joined: Tuesday 01 December 2015 8:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Volumio Connector for Domoticz

Post by Ries »

emme wrote: Friday 22 June 2018 10:17 )MQTT is a REALLY good solution and widely open to almost everything!!!
I am really interested in your detailed approach!
Version 3.9639
Platform: Jessie lite
Hardware: Raspberry pi 3B; RFXCOM; Weather Underground; Dummy; OpenZwave USB; Fritzbox Callmonitor via LAN interface; System Alive Checker (Ping); Philips Hue Bridge; Atag One Thermostat
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Volumio Connector for Domoticz

Post by emme »

Ciao,

here it is...
Cattura-1.jpg
Cattura-1.jpg (77.76 KiB) Viewed 3504 times
please note you have to configure:
MPD in and MPD out with the IP:port (6600) of your volumio device
domoticz/out and domoticz/in with the IP and topicz of your mosquitto server (could be the same as Domoticz box)
in dzSetVolume - set the ID for the custom device for volume control (a dimmer)
in dzSetArtistInfo - set the ID for the custom device for text (act as a display)
in getVolumeSet - set the ID for the custom device for volume control (a dimmer) - the same as per dzSetVolume

here is how it woks:
MPD.in is activated at any chanage in the volumio state
getVolume acquire the volume status and then dzSetVolume convert it into the json formatted command for MQTT, rbe is used to ensure no duplicated values are sent and finally it goes through MQTT to domoticz
dzSetArtist convert Artist Name and song Title into a json formatted command for MQTT rbe is used to ensure no duplicated values are sent and finally it goes through MQTT to domoticz
in the meantime, domoticz/out push ALL status form domoticz, so it gets converted into a JSON and then getVolumeSet intercept the volume device and update volumio via MPD

getVolume and dzSetVolume could be merged into a single function, but I have a dashboard also, so, my layout is quite different (i've created this one only for this post :P :P )

here is the nodeRed flow to import from clipboard

Code: Select all

[{"id":"e3c13c75.d0dcb","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"71c0613f.05d81","type":"mpd in","z":"e3c13c75.d0dcb","name":"","topic":"","server":"3ce54245.d0712e","x":87,"y":78,"wires":[["32c5f555.1475ca","e8d09e01.5c04f","564017f4.cfdfa8"]]},{"id":"32c5f555.1475ca","type":"debug","z":"e3c13c75.d0dcb","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":285.4753112792969,"y":35.587188720703125,"wires":[]},{"id":"35032ee8.133e22","type":"catch","z":"e3c13c75.d0dcb","name":"","scope":null,"x":97.1201171875,"y":36.587188720703125,"wires":[["32c5f555.1475ca"]]},{"id":"e8d09e01.5c04f","type":"function","z":"e3c13c75.d0dcb","name":"getVolume","func":"\nmsg.payload = msg.payload.status.volume;\n\nreturn msg;","outputs":1,"noerr":0,"x":293.57464599609375,"y":82.6781005859375,"wires":[["4ae356ac.60e838"]],"outputLabels":["Volume"]},{"id":"4ae356ac.60e838","type":"function","z":"e3c13c75.d0dcb","name":"dzSetVolume","func":"msg.payload = {\"command\": \"switchlight\", \"idx\": 1031, \"switchcmd\": \"Set Level\", \"level\": msg.payload};\n\nreturn msg;","outputs":1,"noerr":0,"x":465.1201171875,"y":116.587158203125,"wires":[["3f675acf.e26506"]]},{"id":"564017f4.cfdfa8","type":"function","z":"e3c13c75.d0dcb","name":"dzSetArtistInfo","func":"if (msg.payload.status.state == \"play\") {\n    msg.payload = {\"command\": \"udevice\", \"idx\": 1071, \"svalue\": msg.payload.currentsong.Name + \" ~ \" + msg.payload.currentsong.Title};\n}\nelse {\n    msg.payload = {\"command\": \"udevice\", \"idx\": 1071, \"svalue\": \"STOP\"};\n}\nreturn msg;","outputs":1,"noerr":0,"x":317.1201171875,"y":161.587158203125,"wires":[["45ea63df.fdf7cc"]]},{"id":"3f675acf.e26506","type":"rbe","z":"e3c13c75.d0dcb","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":640.1201171875,"y":130.587158203125,"wires":[["1362ebc8.cc0f44"]]},{"id":"45ea63df.fdf7cc","type":"rbe","z":"e3c13c75.d0dcb","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":506.1201171875,"y":163.587158203125,"wires":[["1362ebc8.cc0f44"]]},{"id":"1362ebc8.cc0f44","type":"mqtt out","z":"e3c13c75.d0dcb","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"e29315fb.89af68","x":802,"y":152,"wires":[]},{"id":"511a0b29.b96c44","type":"mpd out","z":"e3c13c75.d0dcb","name":"","topic":"","server":"3ce54245.d0712e","x":622.5,"y":250,"wires":[[]]},{"id":"b2a058cb.56fb38","type":"mqtt in","z":"e3c13c75.d0dcb","name":"","topic":"domoticz/out","qos":"2","broker":"e29315fb.89af68","x":98,"y":215,"wires":[["3f69c946.af4a56"]]},{"id":"3f69c946.af4a56","type":"json","z":"e3c13c75.d0dcb","name":"","property":"payload","action":"obj","pretty":true,"x":258.77272033691406,"y":237,"wires":[["4c9f9d89.aaef54"]]},{"id":"4c9f9d89.aaef54","type":"function","z":"e3c13c75.d0dcb","name":"getVolumeSet","func":"if (msg.payload.idx == 1031) {\n    msg.payload = \"setvol \" + msg.payload.Level\n    return msg;\n}\n","outputs":1,"noerr":0,"x":435.5,"y":215,"wires":[["511a0b29.b96c44"]],"outputLabels":["msg object"]},{"id":"3ce54245.d0712e","type":"mpd-server","z":"","host":"192.168.0.15","port":"6600"},{"id":"e29315fb.89af68","type":"mqtt-broker","z":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]
Ciao
M
The most dangerous phrase in any language is:
"We always done this way"
WilliamB
Posts: 3
Joined: Saturday 12 January 2019 14:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Volumio Connector for Domoticz

Post by WilliamB »

Hi Emme,

Thanks for your flow!
I've installed Node-RED and MQTT and imported your flow. Thereafter I've put in al the right variables and I got the notification 'connected' on MPD and domoticz, but no signs go to Domoticz. I ain't see anything in the log.
Did I forgot something? Do I have to do extra settings on Volumio? Hopefully you can help me into the right direction.
WilliamB
Posts: 3
Joined: Saturday 12 January 2019 14:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Volumio Connector for Domoticz

Post by WilliamB »

I don't know what happened but it is working now. Unfortunately, I do not know the cause ..
But thanks again for the flow. Works great!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest