Welcome to Domotique-fibaro

 

Inscrivez-vous maintenant pour accéder à toutes nos fonctionnalités. Une fois inscrit et connecté, vous serez en mesure de contribuer à ce site en soumettant votre propre contenu ou en répondant au contenu existant. Vous serez en mesure de personnaliser votre profil, de recevoir des points de réputation comme une récompense pour la soumission de contenu, tout en communiquant avec d'autres membres via votre boîte de réception privée, et bien plus encore! Ce message sera supprimé une fois que vous vous êtes connecté.

 

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

yoim

scenes not working with my variable

Hi,

 

I have external lights. I use geolocation with ifttt. When I arrive near my house my lights turn on automatically. But it must light up when it is dark. At sunset.

 

I created one variable :

 

Screen Shot on 2017-02-10 at 17-01-41.png

 

 

 

I created 3 scenes.

 

First scene :

Screen Shot on 2017-02-10 at 16-58-10.png

 

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

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
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) == fibaro:getValue(1, "sunsetHour")) )
)
then
	fibaro:setGlobal("ext", "1");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
startSource["type"] == "other"
)
then
	fibaro:setGlobal("ext", "1");
end

end

 

My first scene 

Sets my variable to 1 when the sun goes down

 

My second scene sets my variable to 0 when the sun rises.

 

Screen Shot on 2017-02-10 at 17-04-17.png

 

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

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
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) == fibaro:getValue(1, "sunriseHour")) )
)
then
	fibaro:setGlobal("ext", "0");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
startSource["type"] == "other"
)
then
	fibaro:setGlobal("ext", "0");
end

end

And My third scene that executes the lighting of my lights when ext = 1 and that the sun goes down.

 

Screen Shot 2017-02-10 at 17.07.33.png

 

Citation

--[[
%% properties
%% weather
%% events
%% globals
ext
--]]

local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getGlobalValue("ext")) == tonumber("1") )
or
startSource["type"] == "other"
)
then
	fibaro:call(32, "turnOn");
end

 

 

I have a problem, It makes day or night my scene of lighting my lights work all the time. I don't understand.

One idea ? if you can help me please.

 

Thx.

Modifié par yoim
0

Partager ce message


Lien à poster
Partager sur d’autres sites

Hi, 

 

I think you don't need the global. 

Create a scene with LUA and try this. I don't sure, sorry for the errors ;-) 

 

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

local source = fibaro:getSourceTrigger()

function Run()
    -- Hour of the day
    local Hour = tonumber(os.date("%H:%M"))
    fibaro:debug("Hour : " ..Hour)

    -- Time Sunset / Sunrise
    local sunset = tonumber(fibaro:getValue(1, "sunsetHour"))
    local sunrise = tonumber(fibaro:getValue(1, "sunriseHour"))
    fibaro:debug("Sunrise : "..sunrise.. " - Sunset : " ..sunset)

    if Hour == sunset then
        fibaro:call(32, "turnOn")
    elseif Hour == sunrise then
        fibaro:call(32, "turnOff")
    else
        fibaro:debug("Not Sunrise - Not Sunset")
    end
end

-- Main Loop
if source["type"] == "autostart" or source["type"] == "other" then
    Run()
end

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Big thx Pepite for your response.

 

I try this tonight. Sunrise and sunset not working with graphic bloc ?

it is necessary to use that the LUA.

 

Soon.

 

 

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

i have a  error on line 14 :

 

[DEBUG] 22:59:26: line 14: attempt to concatenate local 'Hour' (a nil value)

line 14 is :

 

   fibaro:debug("Hour : " ..Hour)

one idea ?

 

thx

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Hi,

 

Sorry, it's my fault ;-)

"tonumber" doesn't work with os.date and sunsetHour, sunriseHour

 

Try with this

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

local source = fibaro:getSourceTrigger()

function Run()
    -- Hour of the day
    local Hour = os.date("%H:%M")
    fibaro:debug("Hour : " ..Hour)

    -- Time Sunset / Sunrise
    local sunset = fibaro:getValue(1, "sunsetHour")
    local sunrise = fibaro:getValue(1, "sunriseHour")
    fibaro:debug("Sunrise : "..sunrise.. " - Sunset : " ..sunset)

    if Hour == sunset then
        fibaro:call(32, "turnOn")
    elseif Hour == sunrise then
        fibaro:call(32, "turnOff")
    else
        fibaro:debug("Not Sunrise - Not Sunset")
    end
end

-- Main Loop
if source["type"] == "autostart" or source["type"] == "other" then
    Run()
end

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Ok perfect

I try now and my lights not working. It's normal it's day ;)

i tried tonight but it's going to be ok.

 

Thx.

 

Soon.

 

 

1

Partager ce message


Lien à poster
Partager sur d’autres sites
I thought everything was good but the light launch did not work.

 

[DEBUG] 23:28:40: Hour : 23:28
[DEBUG] 23:28:40: Sunrise : 08:07 - Sunset : 18:29
[DEBUG] 23:28:40: Not Sunrise - Not Sunset
[DEBUG] 23:28:48: Hour : 23:28
[DEBUG] 23:28:48: Sunrise : 08:07 - Sunset : 18:29
[DEBUG] 23:28:48: Not Sunrise - Not Sunset

 

hmm it's crazy ! the code is correct.

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Hi, no problem in fact. You try the code after the sunset then the light dont turnOn.
You want :
- at sunset : turnOn the light
- between sunset and sunrise : light stay on
- at sunrise : light turn off
That s it ??

0

Partager ce message


Lien à poster
Partager sur d’autres sites

 

Hi,

 

The light comes on when I start the scene between sunset and sunrise. After the sunrise, even if the scene is launched, the light does not light up.

I working with ifttt location.

 

You understand ?

 

Thx for your response ;)

0

Partager ce message


Lien à poster
Partager sur d’autres sites

i may be finding the solution.

Correct me if you think i m wrong.

 

I replace == by > and  i think it works.

 

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

local source = fibaro:getSourceTrigger()

function Run()
    -- Hour of the day
    local Hour = os.date("%H:%M")
    fibaro:debug("Hour : " ..Hour)

    -- Time Sunset / Sunrise
    local sunset = fibaro:getValue(1, "sunsetHour")
    local sunrise = fibaro:getValue(1, "sunriseHour")
    fibaro:debug("Sunrise : "..sunrise.. " - Sunset : " ..sunset)

    if Hour > sunset then
        fibaro:call(32, "turnOn")
    elseif Hour > sunrise then
        fibaro:call(32, "turnOff")
    else
        fibaro:debug("Not Sunrise - Not Sunset")
    end
end

-- Main Loop
if source["type"] == "autostart" or source["type"] == "other" then
    Run()
end

I try tonight, sunset ;)

 

Soon. 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Ok i Understand you are right wirh the compare.
Try tonight and it miss a setTimeout in the main loop for start the scene every X minutes

0

Partager ce message


Lien à poster
Partager sur d’autres sites

All is ok for me. Big thx for your help.

You can tell me more about setTimeout please ?

 

Soon.

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Hi, the scene is ok but only 1 time i think. When you try you push on start and the scene runs.
For exemple, at sunrise the light turnOff ?

0

Partager ce message


Lien à poster
Partager sur d’autres sites

yes my scene working. When i launch after sunrise, the light turnOff.

That's what I wanted, it's perfect.
what's setTimeout please ?

 

Soon.

 


 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Hi,

 

But You start the scene manually ? how your scene is triggered ? If your scene is triggered by another device or other, it's OK

Because the scene doesn't loop, it's work only manually or triggered.

SetTimeout cans loop the scene, look under the code like this and look the time of the debug  ;-)

 

I add :

local delay = 60 -- in seconds

and in the function :

setTimeout(Run, delay*1000)

 

setTimeout : https://www.domotique-fibaro.fr/topic/4933-settimeout/

 


 

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


local source = fibaro:getSourceTrigger()
local delay = 60 -- in seconds

function Run()
    -- Hour of the day
    local Hour = os.date("%H:%M")
    fibaro:debug("Hour : " ..Hour)

    -- Time Sunset / Sunrise
    local sunset = fibaro:getValue(1, "sunsetHour")
    local sunrise = fibaro:getValue(1, "sunriseHour")
    fibaro:debug("Sunrise : "..sunrise.. " - Sunset : " ..sunset)

    if Hour > sunset then
        fibaro:call(32, "turnOn")
    elseif Hour > sunrise then
        fibaro:call(32, "turnOff")
    else
        fibaro:debug("Not Sunrise - Not Sunset")
    end
    setTimeout(Run, delay*1000)
    
end

-- Main Loop
if source["type"] == "autostart" or source["type"] == "other" then
    Run()
end

 

0

Partager ce message


Lien à poster
Partager sur d’autres sites

Yeah, i understand. Thx for your help ;)

 

 

Your information has been valuable to me. Everything works fine.

 

Soon.

0

Partager ce message


Lien à poster
Partager sur d’autres sites