Aller au contenu
gargamel01000

Aide Code Lua Et Wallplug Pour Coupure Multiroom

Recommended Posts

Bonjour à  tous,

 

Je sollicite votre aide pour un petit bout de code en lua.

Je dispose actuellement de 7 sonos connect amp installés dans un rack qui consomment en moyenne 70 watts au repos.

L'objectif est de pouvoir éteindre le système pendant les journées de travail, c'est à  dire démarrage tous les jours du système multiroom à  17h00 et coupure à  08h00 si jour chomé = NON

 

voici mon bout de code, pensez vous que cela puisse fonctionner 

--[[
%% autostart
%% properties
%% events
%% globals
JourChome
--]]

local currentDate = os.date("*t");
if (
 ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "17:00") )
)
then
	fibaro:call(150, "turnOn");
end
if (
 ( fibaro:getGlobalValue("JourChome") == "NON" )
and
 ( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "08:10") )
)
then
	fibaro:call(150, "turnOff");
end

Merci pour votre aide

Partager ce message


Lien à poster
Partager sur d’autres sites

Alors

 

Ton script actuel ne fonctionnera que :

  1. Au démarrage de ta box ou sauvegarde de ton script
  2. Lorsque la variable JourChome va changer

Donc à  17h00 et 8h00 rien ne se passera.

 

Voici donc une proposition .. NON TESTEE mais que devrait te donner une bonne base, voir plus.

--[[
%% autostart
--]]

while true do

	-- date du jours
	local currentDate = os.date("*t")	
	-- heure actuel au format HH:mm
	local heure = string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min)
	-- jour de travail 
	local jourdetravail = fibaro:getGlobalValue("JourChome") == "NON"
	
	if (heure == "17:00") then
	
		-- allumage
		fibaro:call(150, "turnOn")
	
	elseif (heure == "08:00" and jourdetravail) then
	
		-- éteindre
		fibaro:call(150, "turnOff")
		
	end
	
	-- on attend 1 minute
	fibaro:sleep(60*1000)
	
end

Cordialement

Partager ce message


Lien à poster
Partager sur d’autres sites

×