Problème script LUA chauffage

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Problème script LUA chauffage

Message par fenx2002 »

Bonjour à tous

Je rencontre un soucis pour gérer mes radiateurs en fil pilote, plus précisément en ce qui concerne le planning.
Jusqu'à présent je passe par le planning au niveau de l’interrupteur pour gérer les différents « levels » mais j’en ai pas mal pour chaque radiateur et quand je pars en vacances je suis obligé de les passer un par un en « inactif ».

Exemple pour 1 raidateur
Activé Type Date Heure Aléatoire Commande Jours
Oui À l'heure 06:00 Non On (55%) Mer, Sam, Dim
Oui À l'heure 06:35 Non On (25%) Lun, Mar, Jeu, Ven
Oui À l'heure 08:30 Non On (35%) Mer, Sam, Dim
Oui À l'heure 12:30 Non On (45%) Mer, Sam, Dim
Oui À l'heure 15:30 Non On (35%) Mer, Sam, Dim
Oui À l'heure 18:30 Non On (45%) Lun, Mar, Mer, Jeu, Ven, Sam, Dim
Oui À l'heure 20:30 Non On (55%) Lun, Mar, Mer, Jeu, Ven, Sam, Dim
Oui À l'heure 22:30 Non On (45%) Lun, Mar, Mer, Jeu, Ven, Sam, Dim
Oui À l'heure 05:00 Non On (55%) Lun, Mar, Jeu, Ven

J’ai vu qu’il pouvait exister quelque chose il me semble pour passer automatiquement en inactif mais je n’ai pas trouvé vraiment comme cela fonctionnait.

Un ami a un script LUA qui marche mais qui ne met que en On ou Off ses radiateurs. Du coup j’ai essayé de l’adapter sur le mien mais je rencontre une erreur et je ne comprends pas pourquoi.

Cela me met à la ligne 18 donc la 1ère ligne ou il y a le set level "unfinished string near ''Set Level 25''

Voici mon script

Code : Tout sélectionner

function IsWeekend()
     local dayNow = tonumber(os.date("%w"))
     local weekend
     if (dayNow == 0) or (dayNow == 6) then weekend = "true"
     else weekend = "false"
     end 
     return weekend
end

commandArray = {}

	-- get current time
	minutesnow = timenow.min + timenow.hour * 60


	-- PROG RADIATEURS VACANCES
	if(IsWeekend() == "false" and uservariables["HOLIDAYS"] == "true") then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’
	End

	-- PROG RADIATEURS WEEK END
	if(IsWeekend() == "false" and uservariables["HOLIDAYS"] == "false" and timenow.hour == 06 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 10 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 35’
		commandArray['rad salon rue']='Set Level 35’
		commandArray[‘Rad Chloé’]=‘Set Level 35’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 35’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 12 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 35’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 14 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 35’
		commandArray['rad salon rue']='Set Level 35’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 35’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 17 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 35’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 19 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 22 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 02 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 04 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’
	End

	-- PROG RADIATEURS SEMAINE

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 05 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’	
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 06 and timenow.min == 30) then

		commandArray[‘Rad CH1’]=‘Set Level 25’
	End


	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 07 and timenow.min == 15) then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’	
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 17 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 55’
		commandArray['rad salon rue']='Set Level 55’
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 21 and timenow.min == 30) then
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 22 and timenow.min == 30) then
		commandArray['Salon jardin']='Set Level 25’
		commandArray['rad salon rue']='Set Level 25’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 23 and timenow.min == 00) then
		commandArray[‘Rad CH1’]=‘Set Level 25’
	End

	if(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 02 and timenow.min == 30) then
		commandArray[‘Rad Chloé’]=‘Set Level 55’
		commandArray[‘Rad CH1’]=‘Set Level 55’
		commandArray[‘Rad Tristan']='Set Level 55’
	End

	iif(IsWeekend() == "false" and (uservariables["HOLIDAYS"] == "false" and timenow.hour == 04 and timenow.min == 00) then
		commandArray[‘Rad Chloé’]=‘Set Level 25’
		commandArray[‘Rad CH1’]=‘Set Level 25’
		commandArray[‘Rad Tristan']='Set Level 25’

	End

	
	return commandArray
Pourtant il me semble bien avoir vu et lu sur les forums que cette commande est écrite de cette façon

Auriez vous une idée? (soit pour tout passer en inactif très rapidement, soit pour faire marcher le script...)

Merci d'avance
Chrominator
Messages : 1042
Inscription : 19 déc. 2015, 07:29
Localisation : France

Re: Problème script LUA chauffage

Message par Chrominator »

Je peux me tromper, mais on dirait que tu utilises 2 caractères différents pour l'apostrophe qui délimite les littéraux.

Je vois le caractère ' qui est normalement sur la touche 4 du clavier AZERTY français, mais aussi un autre caractère qui me paraît incliné vers la gauche.
Quand on vérifie le code de ce caractère, on voit qu'il est différent de l'apostrophe normal qui porte le code 0x27.
Le caractère UTF-8 placé à la fin a le code 0xe28099, ce qui provoque l'erreur car c'est 0x27 qui est attendu.
Capture.PNG
Capture.PNG (8.81 Kio) Consulté 4798 fois

A mon avis, tu utilises un éditeur genre traitement de texte qui fait de jolies choses mais qui n'est pas utilisable pour écrire du code.
Je te recommande Notepad++ si tu es sous Windows. https://notepad-plus-plus.org/
Un bon frein vaut mieux que deux sparadraps.

Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Re: Problème script LUA chauffage

Message par fenx2002 »

Hello
Merci déjà pour ta réponse
Je suis sur MAC et j'édite mon fichier LUA avec Textedit qui doit etre selon moi l'équivalent du notepad.

Par contre j'ai copié collé le code sous word pour le remettre ici et c'est peut être cela qui a changé?
lmet
Messages : 252
Inscription : 30 juin 2017, 18:16
Localisation : Val d'Oise
Contact :

Re: Problème script LUA chauffage

Message par lmet »

Bonjour,

En modifiant comme indiqué par chrominator l'erreur disparait dans l'éditeur.

Je vois aussi que tu utilises des variables "true" et "false" en les affectant ainsi tu les transformes en chaines ce qui n'est pas faux dans l'absolu.
En enlevant les " tu auras des variables de type boolean true et false beaucoup moins gourmandes en mémoire.
Domoticz : V4.10717
Zigate : V4.11230 plugin:4.5.4 firmware:031a
Mon petit blog domotique
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Re: Problème script LUA chauffage

Message par fenx2002 »

ah top ce soir j'essaye les modifs déjà / Merci beaucoup

par contre je n'ai pas compris exactement le truc sur boolean?

J'ai créé une variable utilisateur que je modifie quand je pars en vacances ou pas mais du coup sans mettre les guillemets il va quand meme savoir si c'est true or false?
lmet
Messages : 252
Inscription : 30 juin 2017, 18:16
Localisation : Val d'Oise
Contact :

Re: Problème script LUA chauffage

Message par lmet »

Dans l'absolu cela fonctionne mais ce n'est pas optimisé.
Je ne parle pas des variables utilisateur qui fonctionnent différemment mais des variables boolean en général.
true et false font partie du langage lua tu peux donc écrire :

Code : Tout sélectionner

function IsWeekend()
     local dayNow = tonumber(os.date("%w"))
     local weekend
     if (dayNow == 0) or (dayNow == 6) then 
            weekend = true
     else 
            weekend = false
     end 
     return weekend
end

if(IsWeekend() == false and uservariables["HOLIDAYS"] == "true") then ... 
Domoticz : V4.10717
Zigate : V4.11230 plugin:4.5.4 firmware:031a
Mon petit blog domotique
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Re: Problème script LUA chauffage

Message par fenx2002 »

Ok merci
Par contre je garde bien les 2 signes == devant if(IsWeekend() == false?
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Re: Problème script LUA chauffage

Message par fenx2002 »

Re Hello

bon pb résolu sur ce soucis de set level effectivement la parenthèse n'était pas bonne
Par contre j'ai un autre problème désormais

2018-12-28 21:38:00.410 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_all.lua: /home/pi/domoticz/scripts/lua/script_time_all.lua:20: ']' expected near 'Set'

Pourtant il ne me semble pas avoir oublié une parenthèse... une idée?

Merci d'avance je pars demain en vacances et j'aurai aimé pourvoir tout mettre en place avant...
@+
lmet
Messages : 252
Inscription : 30 juin 2017, 18:16
Localisation : Val d'Oise
Contact :

Re: Problème script LUA chauffage

Message par lmet »

Peux-tu remettre le code de ton script en faisant un copier/coller à partir de Textedit ?
Et mettre la ligne où l'erreur se produit.
Domoticz : V4.10717
Zigate : V4.11230 plugin:4.5.4 firmware:031a
Mon petit blog domotique
fenx2002
Messages : 30
Inscription : 04 avr. 2017, 11:41

Re: Problème script LUA chauffage

Message par fenx2002 »

pourquoi pas en time? car je lui demande des actions selon des horaires non?

du coup si je le passe en device il ne va pas tourner toutes les minutes?
j'ai fait en device pour voir selon la manip que tu as décrite mais j'ai plein d'erreurs

le problème vient de la ligne suivante
commandArray['rad Chloe’]='Set Level 25'

c'est comme s'il n'aimait pas la majuscule ou autre
Répondre