Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

run scene based on date variable


Question

Posted

Hi all, would really appreciate any help which can be provided.

Using HC3, I want to store a date as a variable and then at sunset of the following day run a scene.

Was thinking of storing the date as global variable and then I need to run a scene which adds 1 day to the stored date if it matches then run scene.

 

Global Variable Name Is HoildayDate = "11/20/20"

 

I am stuck on how to manipulate the stored value to be able to trigger the scene.

 Thank you

 

Recommended Posts

  • 0
  • Inquirer
  • Posted
    1 hour ago, Bodyart said:

    Please login or register to see this code.

     

    moved it in to a qa and it works perfectly thank you, is there a way of running it from a scene instead of a quickapp? 

    • 0
    Posted

    Why would you like it to run from a scene?!?

    • 0
  • Inquirer
  • Posted

    hmm as i will be running it on a timer in a scene and thought it would be neater to keep it all in one scene 

    • 0
  • Inquirer
  • Posted

    this has stopped working have i got a typo somewhere?

     
    function QuickApp:checkYomTov()
        http =net.HTTPClient()
        local today = os.time() --+ (86400*94) -- used to check for forward dates for testing purposes
        local year = os.date("%Y",today)
        local month = os.date("%m",today)
        local day = os.date("%d",today)
        local checkdate = year.."-"..month.."-"..day
        local tomorrow = today + 86400
        local yearTomorrow = os.date("%Y",tomorrow)
        local monthTomorrow = os.date("%m",tomorrow)
        local dayTomorrow = os.date("%d",tomorrow)
        local checkdateTomorrow = yearTomorrow.."-"..monthTomorrow.."-"..dayTomorrow
        
        local httpstring = "https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&geonameid=2643123"
        local address  = httpstring.."&year="..year.."&month="..month
        print (address)
        http:request(address,{options={headers={Accept="application/json"},method='GET'},
                success = function(response)
                    local cal=json.decode(response.data) 
                    for i=1,#cal.items do
                        if cal.items[i].date==checkdate then
                            if cal.items[i].yomtov==nil then cal.items[i].yomtov=false end
                            print (cal.items[i].yomtov)
                            if cal.items[i].yomtov==true then 
                                print('Today is Yom Tov: ',cal.items[i].date)
                            else
                                print('Today is NOT Yom Tov: ',cal.items[i].date)
                            end
                            --print('Yomtov is',tostring(cal.items[i].yomtov))
                            --if cal.items[i].yomtov==nil then cal.items[i].yomtov=false end
                            --print('Yomtov is today: ',cal.items[i].date)
                        elseif cal.items[i].date==checkdateTomorrow then
                            if cal.items[i].yomtov==nil then cal.items[i].yomtov=false end
                            if cal.items[i].yomtov==true then 
                                print('Tomorrow is Yom Tov: ',cal.items[i].date)
                            else
                                print('Tomorrow is NOT Yom Tov: ',cal.items[i].date)
                            end
                        end
                    end
                end,
                error = function(error)
                    fibaro.debug("error: "..json.encode(error))
                end
            }
        )
    end
        
    function QuickApp:onInit()
        self:debug("onInit")
        self:checkYomTov()
    end
    • 0
  • Inquirer
  • Posted

    The code works if it cal.items[i].yomtov==true 

    however i cant get it to work if it is not true can you please advise?

    • 0
    Posted (edited)

    Hi @Jay Ess,

     

    insert before working with the value of  cal.items[i].yomtov

    simple test:

                    if cal.items[i].yomtov==nil then cal.items[i].yomtov=false end
    Edited by Bodyart
    • 0
  • Inquirer
  • Posted

    have a weird sitution going on here i am using the following code to pick up hebrew dats by json,

    the line print ("A") runs before the function whihc gets callled higher up, can anyone please advise what is going wrong?

     

    yomTovToday = ""
    yomTovTomorrow = ""
    adjustYomTovName = ""
    hR = ""
    ytR = "false"
    ecR = "false"
    erevchagVariableName ="erevChag"
    yomtovVariableName = "yomtov"
    getErevChagValue = fibaro.getGlobalVariable(erevchagVariableName)
    getYomTovValue = fibaro.getGlobalVariable(yomtovVariableName)
    getHebrewDateValue = fibaro.getGlobalVariable("hebrewdate")
     
    function QuickApp:checkYomTov()
        --print ("Y "..getYomTovValue.." E "..getErevChagValue.." H "..getHebrewDateValue)
        local http =net.HTTPClient()
        local testyomtovdate = fibaro.getGlobalVariable("testYomTovDate")
        local today
        --adjust the day for sunset ie. after sunset it is the next day
        local sunset = fibaro.getValue(1"sunsetHour")
        local currentTime =os.date("%H:%M")
        if currentTime >= sunset then
            today = os.time() + 86400 + (86400*tonumber(testyomtovdate))
        else
            today = os.time() + (86400*tonumber(testyomtovdate))
        end 
        local year = os.date("%Y",today)
        local month = os.date("%m",today)
        local day = os.date("%d",today)
        local checkdate = year.."-"..month.."-"..day
        local tomorrow = today + 86400
        local yearTomorrow = os.date("%Y",tomorrow)
        local monthTomorrow = os.date("%m",tomorrow)
        local dayTomorrow = os.date("%d",tomorrow)
        local checkdateTomorrow = yearTomorrow.."-"..monthTomorrow.."-"..dayTomorrow
        local httpstring = "https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&geonameid=2643123&d=on"
        local address  = httpstring.."&year="..year.."&month="..month
        ytR = "false"
        ecR = "false"
        yomTovToday = ""
        yomTovTomorrow = ""
        adjustYomTovName = ""
        print ("1: "..address)
        print ("2: "..checkdate)
        http:request(address,{options={headers={Accept="application/json"},method='GET'},
                success = function(response)
                    local cal=json.decode(response.data) 
                    for i=1,#cal.items 
                        do
                            if cal.items[i].date==checkdate and cal.items[i].category=="hebdate" then
                                --Put Hebrew Date In Variable if it is not already in
                                hR = tostring(cal.items[i].title_orig)
                                if getHebrewDateValue ~= hR then
                                    fibaro.setGlobalVariable("hebrewdate", hR)
                                end 
                            end
                            --Check if today is Yom Tov
                            if cal.items[i].date==checkdate and cal.items[i].category=="holiday" then
                                if cal.items[i].yomtov==true then
                                    ytR="true"
                                end    
                                yomTovToday = tostring(cal.items[i].title)
                            end
                            --Check if tomorrow is Yom Tov
                            if cal.items[i].date==checkdateTomorrow and cal.items[i].yomtov~=nil then
                                ecR="true"
                                yomTovTomorrow = tostring(cal.items[i].title)
                            end
                        end 
                    print (ecR) 
                    self:setYomTovVariables()         
                end,
                error = function(error)
                    fibaro.debug("error: "..json.encode(error))
                end
            }
        ) 
        
        print ("a")    
        --self:setYomTovVariables()
        self:updateView(
            "lblStatus""text""Last Updated: "..os.date("%d/%m/%Y-%H:%M").."<br>Hebrew Date: "..fibaro.getGlobalVariable("hebrewdate").."<br>YomTov: "..fibaro.getGlobalVariable("yomtov").."<br>Erev Chag: "..fibaro.getGlobalVariable("erevChag").."<br>Pesach: "..fibaro.getGlobalVariable("pesach").."<br>Yom Tov Name: "..fibaro.getGlobalVariable("yomtovname")
        )
    end
     
    function QuickApp:setYomTovVariables()
        print ("Yom Tov Today: ytR: "..ytR)
        print ("Yom Tov Tomorrow: ecR: "..ecR)
        print ("Yom Tov Today: "..yomTovToday)
        print ("Yom Tov Tomorrow: "..yomTovTomorrow)
        if ytR == "false" then
            --if yomTov == "true" then
                fibaro.setGlobalVariable(yomtovVariableName, "false")
            --end    
            if ecR =="false" then
                --if erevChag == "true" then
                    fibaro.setGlobalVariable(erevchagVariableName, "false")
                --end
            else
                --if erevChag == "false" then
                    fibaro.setGlobalVariable(erevchagVariableName, "true")
                --end
            end
        else
            --if yomTov == "false" then
                fibaro.setGlobalVariable(yomtovVariableName, "true")
            --end
            --if erevChag == "true" then
                fibaro.setGlobalVariable(erevchagVariableName, "false")
            --end
        end 
        self:setYomTovName()
    end
     
    function QuickApp:setYomTovName()
        if yomTovToday ~= "" then
            adjustYomTovName = yomTovToday
        else
            if yomTovTomorrow ~= "" then
                adjustYomTovName = yomTovTomorrow
            end
        end
        print ("Yom Tov Name: "..adjustYomTovName)
        if adjustYomTovName ~= "" then
            if string.match(adjustYomTovName,"Pesach"then 
                adjustYomTovName="Pesach"
            elseif string.match(adjustYomTovName,"Shavuot"then 
                adjustYomTovName="Shavuot"
            elseif string.match(adjustYomTovName,"Rosh"then 
                adjustYomTovName="Rosh Hashana"
            elseif string.match(adjustYomTovName,"Yom"then 
                adjustYomTovName="Yom Kippur"
            elseif string.match(adjustYomTovName,"Sukkot"then 
                adjustYomTovName="Sukkot"
            elseif string.match(adjustYomTovName,"Shmini"then 
                adjustYomTovName="Shmini Atzeret"
            elseif string.match(adjustYomTovName,"Simchat"then 
                adjustYomTovName="Simchat Torah"
            end
        end
        local YomTovName = fibaro.getGlobalVariable("yomtovname")
        print ("Variable Yom Tov Name: "..YomTovName)
        if YomTovName ~= adjustYomTovName then
            fibaro.setGlobalVariable("yomtovname", adjustYomTovName)
        end
        local PesachVariable = fibaro.getGlobalVariable("pesach")
        local SukkotValriable = fibaro.getGlobalVariable("sukkot")
        
        if adjustYomTovName == "" then    
            if PesachVariable=="true" then 
                fibaro.setGlobalVariable("pesach""false")
            end
            if SukkotValriable=="true" then
                fibaro.setGlobalVariable("sukkot""false")
            end
        else
            if adjustYomTovName=="Pesach" then
                if PesachVariable == "false" then 
                    fibaro.setGlobalVariable("pesach""true")
                end
            end
            if adjustYomTovName=="Sukkot" then
                if SukkotValriable=="false" then
                    fibaro.setGlobalVariable("sukkot""true")
                end
            end
        end
        print("END")
    end
     
    function QuickApp:onInit()
        self:debug("onInit")
        self:checkYomTov()
        setInterval(
            function()
                self:checkYomTov()
            end,
            1000 * 601
        )
    end
     
    • 0
    Posted

    Short answer, net.HTTPClient() is asynchronous.

    See

     

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...