Ca te permettra d'installer les programmes pour curl et de tester ton premier script en bash
Dès que ton script sera fonctionnel, on s'attaquera à le faire toutes les minutes.
N hesite pas à poster ton script, et à poser des questions.
Code : Tout sélectionner
#!/bin/bash
result=$(curl -s "http://192.168.1.XX:XXXX/json.htm?type=devices&rid=1"| jq -r .result[].Status)
echo $result
if [ $result = "on" ]
then
curl 'http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=On&level=0'
elif [ $result = "off" ]
then
curl 'http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=Off&level=0'
fi
Code : Tout sélectionner
result=$(curl -s "http://192.168.1.XX:XXXX/json.htm?type=devices&rid=1"| jq -r .result[].Status)Code : Tout sélectionner
{
"ActTime" : 1445355555,
"ServerTime" : "2015-10-20 17:39:15",
"Sunrise" : "08:19",
"Sunset" : "18:51",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 10,
"Data" : "On",
"Description" : "",
"Favorite" : 1,
"HardwareID" : 1,
"HardwareName" : "Dongle",
"HardwareType" : "OpenZWave USB",
"HardwareTypeVal" : 21,
"HaveDimmer" : true,
"HaveGroupCmd" : false,
"HaveTimeout" : false,
"ID" : "0000201",
"Image" : "Fireplace",
"IsSubDevice" : false,
"LastUpdate" : "2015-10-20 16:37:02",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "Poêle",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : 7,
"Status" : "On",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "ZWave",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "true",
"Type" : "Lighting 2",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "1"
}
],
"status" : "OK",
"title" : "Devices"
}Code : Tout sélectionner
http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=Off&level=0On va faire ton script en bash et non en lua. C'est pour ça que tu ne vois pas l'intégration dans un script Lua.Gaz a écrit :
Par contre je capte pas le coup de l'intégration dans un script Lua Domoticz
Code : Tout sélectionner
#!/bin/bash
result=$(curl -s "http://192.168.1.XX:XXXX/json.htm?type=devices&rid=1"| jq -r .result[].HaveTimeout)
echo $result
if [ $result = "true " ]
then
curl 'http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=On&level=0'
elif [ $result = "false ]
then
service domoticz restart
fi
Code : Tout sélectionner
{
"ActTime" : 1445367279,
"ServerTime" : "2015-10-20 20:54:39",
"Sunrise" : "08:19",
"Sunset" : "18:51",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"CustomImage" : 0,
"Data" : "Off",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 1,
"HardwareName" : "Dongle",
"HardwareType" : "OpenZWave USB",
"HardwareTypeVal" : 21,
"HaveDimmer" : true,
"HaveGroupCmd" : false,
"HaveTimeout" :[color=#FF0000] false[/color],
"ID" : "0000202",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2015-10-20 11:48:10",
"Level" : 0,
"LevelInt" : 0,
"MaxDimLevel" : 100,
"Name" : "Switch Poêle 2 \"off\"",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "Off",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "ZWave",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Lighting 2",
"TypeImg" : "lightbulb",
"Unit" : 1,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "2"
}
],
"status" : "OK",
"title" : "Devices"
}Pourquoi tu envoies ce curl : " curl 'http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=On&level=0' " ? Il ne te sert à rien, moi je verrais ça (j'ai rajouter les guillemets manquants)Gaz a écrit :2eme copie :
J'ai changer les on/off en true/false car c'est les valeurs qui sont dans le résultat :Code : Tout sélectionner
#!/bin/bash result=$(curl -s "http://192.168.1.XX:XXXX/json.htm?type=devices&rid=1"| jq -r .result[].HaveTimeout) echo $result if [ $result = "true " ] then curl 'http://192.168.1.XX:XXXX/json.htm?type=command¶m=switchlight&idx=1&switchcmd=On&level=0' elif [ $result = "false ] then service domoticz restart fi
http://192.168.1.xx:xxxx/json.htm?type=devices&rid=2
Code : Tout sélectionner
#!/bin/bash
result=$(curl -s "http://192.168.1.XX:XXXX/json.htm?type=devices&rid=1"| jq -r .result[].HaveTimeout)
echo $result
if [ $result = "true" ]
then
sudo service domoticz.sh restart
fi
RPI = Raspberry PiGaz a écrit :Pour info RPI=????