Page 3 sur 8

Re: bibliothèque de fonctions pour scripts LUA

Publié : 29 sept. 2017, 07:23
par landaisbenj
Hello.

Si je fais :

Code : Tout sélectionner

if devicechanged(PIR)=‘On’ then
switchOnFor(‘lumiere, 10’)
end
Comment je fais pour annuler la tempo?

Un simple switchOn suffit?

Re: bibliothèque de fonctions pour scripts LUA

Publié : 29 sept. 2017, 14:42
par vil1driver
La syntaxe est mauvaise..

Sinon oui
viewtopic.php?p=27870#p27870

Re: bibliothèque de fonctions pour scripts LUA

Publié : 29 sept. 2017, 15:42
par landaisbenj
Oui c’était un brouillon. J'y ai pensé au réveil et du coup c’était pas clair dans mon cerveau. J'aurai pu tester aussi mais c'est moins social lol

Par contre pour la syntaxe en vrai j'avais mis ('lumiere', 10) mais je viens de voir mon erreur dans mes logs de ce matin.

Merci.

Re: bibliothèque de fonctions pour scripts LUA

Publié : 21 nov. 2017, 15:34
par jackslayter
à ajouter pour exécuter à une l'heure ou minute ou (seconde), précise

Code : Tout sélectionner

--time.hour ou time.min ou time.sec
--ex : if (time.hour == 17 and time.min == 05) then
time = os.date("*t")

Re: bibliothèque de fonctions pour scripts LUA

Publié : 21 nov. 2017, 16:16
par vil1driver

Code : Tout sélectionner

if heure == '17:05' then
;)

Re: bibliothèque de fonctions pour scripts LUA

Publié : 21 nov. 2017, 17:12
par jackslayter
Ça marche si on met

Code : Tout sélectionner

heure < '17:30' and heure > '19:55' then
?

Et pour exécuter toutes les 3 heures et 43 minutes ?

Re: bibliothèque de fonctions pour scripts LUA

Publié : 21 nov. 2017, 18:25
par vil1driver
Bah non ça ne marche pas :| peut importe la méthode.
Sauf en remplaçant > par < et inversement ou and par or

Effectivement pour utiliser les modulo, time.hour et time.min est impératif
Je ferai l'ajout ;)
Merci

Re: bibliothèque de fonctions pour scripts LUA

Publié : 21 nov. 2017, 18:43
par jackslayter
Merci à toi

Re: bibliothèque de fonctions pour scripts LUA

Publié : 11 déc. 2017, 23:12
par arno16
Hello,

Merci Vil1driver pour cette bibliotheque LUA tres pratique.
Je suis reparti de celle-ci pour créer une nouvelle fonction pour récuperer les schedules de mes switchs.
Mon objectif est de mettre en place plusieurs schedules sur differents switch et d'activer l'un ou l'autre via a un selector switch.

J'ai pris pour example la fonction jsonInfos

Code : Tout sélectionner

function jsonInfos(device)
	local rid = assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=devices&rid='..otherdevices_idx[device]..'"'))
	local list = rid:read('*all')
	rid:close()
	return json:decode(list).result[1]
end
et ma fonction est la suivante

Code : Tout sélectionner

local function getDevicesSchedule()
    print('top1')
    local rid = assert(io.popen(curl..'-u '..domoticzUSER..':'..domoticzPSWD..' "'..domoticzURL..'/json.htm?type=schedules&filter=device"'))
    print('top2')
    local list = rid:read('*all')
    print('top3')
    rid:close()
    print('top4')
    return json:decode(list).result
end
c'est une v1, il me reste encore a filtrer le resultat pour un device donné, mais j'ai déja un gros probleme de performance avec l'operation "rid:read('*all')" qui prend 11 secondes!
2017-12-11 22:46:54.222 dzVents: Planning selector:Planning Eco-Confort
2017-12-11 22:46:54.222 dzVents: top1
2017-12-11 22:46:54.225 dzVents: top2
2017-12-11 22:47:04.206 Error: EventSystem: Warning!, lua script sc_planning has been running for more than 10 seconds
2017-12-11 22:47:04.207 (Chauffage_RDC_Devices) Light/Switch (Planning Eco-Confort)
2017-12-11 22:47:04.226 dzVents: top3
2017-12-11 22:47:04.226 dzVents: top4
2017-12-11 22:47:04.232 dzVents: table = {
[1] = {
["IsThermostat"] = "false";
["TimerID"] = 2;
["TimerTypeStr"] = "On Time";
["DevName"] = "Mode_Chauffage_RDC";
["Days"] = 128;
["TimerCmd"] = 0;
["Occurence"] = 0;
["Month"] = 0;
["Level"] = 30;
["Type"] = "Device";
["ScheduleDate"] = "2017-12-12 07:00:00";
["TimerType"] = 2;
["MDay"] = 0;
["Time"] = "07:00";
["Active"] = "true";
["DeviceRowID"] = 10;
["Hue"] = 0;
["Randomness"] = "false";
["Date"] = "";
};
[2] = {
["IsThermostat"] = "false";
["TimerID"] = 1;
["TimerTypeStr"] = "On Time";
["DevName"] = "Mode_Chauffage_RDC";
["Days"] = 128;
["TimerCmd"] = 0;
["Occurence"] = 0;
["Month"] = 0;
["Level"] = 20;
["Type"] = "Device";
["ScheduleDate"] = "2017-12-11 23:30:00";
["TimerType"] = 2;
["MDay"] = 0;
["Time"] = "23:30";
["Active"] = "true";
["DeviceRowID"] = 10;
["Hue"] = 0;
["Randomness"] = "false";
["Date"] = "";
};
};
pour info la fonction est appelée dans un script device avec cette commande "print(table_show(getDevicesSchedule()))"

J'ai vérifié si j'avais le meme probleme de perf avec la fonction d'origine avec "print(table_show(jsonInfos(device[2])))"
=> meme probleme de perf
2017-12-11 22:59:49.567 User: Admin initiated a switch command (13/Planning Eco-Confort/Set Level)
2017-12-11 22:59:49.721 dzVents: table = {
["Planning Eco-Confort"] = "De Matin";
};
2017-12-11 22:59:49.721 dzVents: Planning selector:Planning Eco-Confort
2017-12-11 22:59:59.704 Error: EventSystem: Warning!, lua script sc_planning has been running for more than 10 seconds
2017-12-11 22:59:59.706 (Chauffage_RDC_Devices) Light/Switch (Planning Eco-Confort)
2017-12-11 22:59:59.728 dzVents: table = {
["Unit"] = 1;
["LevelOffHidden"] = true;
["Data"] = "Set Level: 20 %";
["Image"] = "ComputerPC";
["HardwareName"] = "Chauffage_RDC_Devices";
["Notifications"] = "false";
["LastUpdate"] = "2017-12-11 22:59:49";
["idx"] = "13";
["BatteryLevel"] = 255;
["HaveTimeout"] = false;
["Description"] = "";
["TypeImg"] = "Light";
["Name"] = "Planning Eco-Confort";
["MaxDimLevel"] = 100;
["SelectorStyle"] = 0;
["SignalLevel"] = "-";
["Level"] = 20;
["StrParam2"] = "";
["AddjMulti2"] = 1;
["HardwareTypeVal"] = 15;
["LevelInt"] = 20;
["HaveGroupCmd"] = true;
["AddjMulti"] = 1;
["LevelActions"] = "||||";
["XOffset"] = "0";
["HardwareType"] = "Dummy (Does nothing, use for virtual switches only)";
["SwitchType"] = "Selector";
["YOffset"] = "0";
["HardwareID"] = 5;
["Used"] = 1;
["Type"] = "Light/Switch";
["SubType"] = "Selector Switch";
["PlanID"] = "0";
["Timers"] = "false";
["IsSubDevice"] = false;
["SwitchTypeVal"] = 18;
["CustomImage"] = 17;
["StrParam1"] = "";
["Status"] = "Set Level: 20 %";
["Favorite"] = 1;
["ShowNotifications"] = true;
["Protected"] = false;
["AddjValue2"] = 0;
["ID"] = "0001405D";
["HaveDimmer"] = true;
["AddjValue"] = 0;
["PlanIDs"] = {
[1] = 0;
};
["UsedByCamera"] = false;
["LevelNames"] = "Off|Repos|De Matin|D'Aprem|Horaire Bureau";
};
Avez vous déja eu ce genre de probleme? Savez vous comment le résoudre?
Je bloque la dessus depuis quelques jours, toute piste pour avancer serait grandement appréciée!

Merci,
Arno

ps: désolé pour tous les accents manquants, sur un clavier qwerty, c'est pas facile :-)

Re: bibliothèque de fonctions pour scripts LUA

Publié : 13 déc. 2017, 08:46
par landaisbenj
Utilise jq lors du curl. Je pense qu'il est installé avec domoticz (mais pas sur) Comme ca tu parse ton retour json directement. (C'est une idée que je ne suis pas sur qu'elle est réalisable, je n'ai pas encore eu l'occasion de le faire)