[LUA] Bibliothèque de fonctions

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
landaisbenj
Messages : 695
Inscription : 12 mars 2017, 19:24

Re: bibliothèque de fonctions pour scripts LUA

Message 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?
Rpbi3b: Domoticz + Homebridge + Monit + Freebox scripts + Shellinabox; Rpbi2: Jarvis
Domoticz: Derniere stable; RFLINK: Dernière stable; Xiaomi Gateway
vil1driver
Messages : 5661
Inscription : 30 janv. 2015, 11:07
Localisation : Rennes (35)

Re: bibliothèque de fonctions pour scripts LUA

Message par vil1driver »

La syntaxe est mauvaise..

Sinon oui
viewtopic.php?p=27870#p27870
MAJ = VIDER LE CACHE(<-Clicable)
/!\Les mises à jour de Domoticz sont souvent sources de difficultés, ne sautez pas dessus
modules.lua

Un ex domoticzien
landaisbenj
Messages : 695
Inscription : 12 mars 2017, 19:24

Re: bibliothèque de fonctions pour scripts LUA

Message 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.
Rpbi3b: Domoticz + Homebridge + Monit + Freebox scripts + Shellinabox; Rpbi2: Jarvis
Domoticz: Derniere stable; RFLINK: Dernière stable; Xiaomi Gateway
jackslayter
Messages : 1040
Inscription : 30 sept. 2014, 14:40
Localisation : Isère (38)

Re: bibliothèque de fonctions pour scripts LUA

Message 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")
Raspberry Pi + RFLink + Domoticz Beta
Oregon - 3x Thgr122Nx / Chacon - micromodule 200w, télécommande 3b et 16b, 2x module 1000w, détecteur de fumée, contact de porte, 2x prise 3500w / OWL - CM180 / TRC02 v2 RGB 3M / Cheap - PIR, contact de porte
vil1driver
Messages : 5661
Inscription : 30 janv. 2015, 11:07
Localisation : Rennes (35)

Re: bibliothèque de fonctions pour scripts LUA

Message par vil1driver »

Code : Tout sélectionner

if heure == '17:05' then
;)
MAJ = VIDER LE CACHE(<-Clicable)
/!\Les mises à jour de Domoticz sont souvent sources de difficultés, ne sautez pas dessus
modules.lua

Un ex domoticzien
jackslayter
Messages : 1040
Inscription : 30 sept. 2014, 14:40
Localisation : Isère (38)

Re: bibliothèque de fonctions pour scripts LUA

Message 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 ?
Raspberry Pi + RFLink + Domoticz Beta
Oregon - 3x Thgr122Nx / Chacon - micromodule 200w, télécommande 3b et 16b, 2x module 1000w, détecteur de fumée, contact de porte, 2x prise 3500w / OWL - CM180 / TRC02 v2 RGB 3M / Cheap - PIR, contact de porte
vil1driver
Messages : 5661
Inscription : 30 janv. 2015, 11:07
Localisation : Rennes (35)

Re: bibliothèque de fonctions pour scripts LUA

Message 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
MAJ = VIDER LE CACHE(<-Clicable)
/!\Les mises à jour de Domoticz sont souvent sources de difficultés, ne sautez pas dessus
modules.lua

Un ex domoticzien
jackslayter
Messages : 1040
Inscription : 30 sept. 2014, 14:40
Localisation : Isère (38)

Re: bibliothèque de fonctions pour scripts LUA

Message par jackslayter »

Merci à toi
Raspberry Pi + RFLink + Domoticz Beta
Oregon - 3x Thgr122Nx / Chacon - micromodule 200w, télécommande 3b et 16b, 2x module 1000w, détecteur de fumée, contact de porte, 2x prise 3500w / OWL - CM180 / TRC02 v2 RGB 3M / Cheap - PIR, contact de porte
arno16
Messages : 2
Inscription : 10 déc. 2017, 22:56

Re: bibliothèque de fonctions pour scripts LUA

Message 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 :-)
landaisbenj
Messages : 695
Inscription : 12 mars 2017, 19:24

Re: bibliothèque de fonctions pour scripts LUA

Message 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)
Rpbi3b: Domoticz + Homebridge + Monit + Freebox scripts + Shellinabox; Rpbi2: Jarvis
Domoticz: Derniere stable; RFLINK: Dernière stable; Xiaomi Gateway
Répondre