its quite ugly way but works imho great
im using this script to search and play interpret for MPSYT youtube player (but could be used for other scripts also)
1/so add one empty selector switch (or normal swtich) without any command
2/create domoticz variable
3/then add this js to theme (modify with your idx and right selector div box path
- so script works append search box to selected swith box
- then run dummy switch to stop previos MPSYT (sh script)
- send search box value to domoticz variable
- then run dummy switch with python script (this script read domoticz variable and send it to mpsyt) (python script)
im not real coder, but it was fun to hack
I know this guide requires some knowledge of domotic and scripting, but maybe could be interesting for someone..
JS theme code
Code: Select all
$("#lSelector80Level7").click(function () {
var mytext = $('#myText').val();
$("<div id='dialog' title='MPSYT SETUP'>text: <input type='text' name='jmeno' id='comm' size='12' placeholder='input'/></div>").appendTo('body').hide();
event.preventDefault();
$("#dialog").dialog({
width: 600,
modal: true,
buttons: [
{
text: "Send",
icon: "ui-icon-about",
click: function( e ) {
var value = $("#comm").val(); //search input value
// stop MPSYT
var stop_url = "http://XXXX/json.htm?type=command¶m=switchlight&idx=80&switchcmd=Set%20Level&level=50";
$.get(stop_url);
var durl = "http://XXXX/json.htm?type=command¶m=updateuservariable&vname=command&vtype=2&vvalue=";
var domoticzurl = durl+value;
// console.log(domoticzurl);
$.get(domoticzurl);
//play MPSYT
var play_url = "http://XXXX/json.htm?type=command¶m=switchlight&idx=699&switchcmd=On";
$.get(play_url);
//set player on yamaha
var yamaha_url = "http://XXXX/json.htm?type=command¶m=switchlight&idx=66&switchcmd=Set%20Level&level=50";
$.get(yamaha_url);
$("#dialog").remove();
//function
}
}
],
close: function(event, ui) {
$("#dialog").remove();
}
});
}); //close click
python script to read variable and play in MPSYT
Code: Select all
#!/usr/bin/python3
import requests
import json
from requests.auth import HTTPBasicAuth
import os
from random import randint
debug = 0
domoticz = 1
random = (randint(1, 9))
custom_var ='http://XXXX/json.htm?type=command¶m=getuservariable&idx=5'
custom_var_json = requests.get(url=custom_var, auth=HTTPBasicAuth('xxx', 'Xxx'), timeout=5)
hodnota = custom_var_json.json()['result'][-1]['Value']
print (hodnota)
cmd = 'mpsyt //' + hodnota + ', ' + str(random) + ', shuffle all > /dev/null < /dev/null &'
os.system(cmd)
print (cmd)
bash script to stop MPSYT
Code: Select all
#! /bin/bash
sudo /usr/bin/pkill mpsyt > /dev/null
sudo /usr/bin/pkill mpv > /dev/null
sudo /usr/bin/pkill python > /dev/null
exit 0