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


Recommended Posts

Posted

Here it is:

--[[
%% properties
14 power
16 power
18 power
54 value
59 value
77 value
123 value
126 value
145 value
147 value
172 value
176 value
221 value
223 value
226 value
228 value
273 value
287 value
292 power
323 power
336 value
341 value
343 value
351 value
370 value
1299 sceneActivation
1292 sceneActivation
78 sceneActivation
88 ui.Slider1.value
88 ui.Label1.value
%% events
%% globals
Dagdelen
Stookseizoen
HuisStatus
%% autostart
--]]
--scenes

--Precense
LocatieGezin         = 287   --on = present
GastBeneden          = 343
GastBoven            = 341
telefoonSjaak        = 70
Vakantie             = 289

--Rond het huis
lightSensorBuVoor   = 126
lightSensorBuAchter = 370
bewegingSensorAchter  = 372
bewegingSensorVoor    = 125
verlFietsenhok      = 100
verlBeeldBuiten     =  34
verlVlag            =  96
verlGastAchterdeur  = 151
stekkerFontein        = 228

--Hal
doorFront           =  54
verlOverloop          =    121
verlHal              =    123
stekkerTrap           = 345
stekkerLedOverloop    = 300
deurHal               =  59
deurbel                  =     64
sonosPlayer              =    212

--Living room
curtainFront        =  48
curtainSideCar      =  50
curtainSideBicycle  =  52
stekkerTV             = 16
stekkerStoelSjaak     = 14
stekkerStoelArleta    = 18
hueKastRechtsSpot     = 323

--Eetkamer
motionSensorEetkamer  =    145
luxSensorEetkamer      =    147
verlEetkamerPlafond = 258
curtainBack         =  44
curtainBackSide     =  46
deurnaarSerre         = 351

--Keuken
keukenPlintLed      =  20
stekkerAfzuigpkap      = 292
sonosSpeaker          = 249

--Hoofdslaapkamer
verlHfdSlpkmr       = 117
deurHfdSlpkmr         = 172

--GastenKamerBoven
deurGastBoven          =    176
verlTafel              =    223
verlBed               = 226
sensorLinksGastBoven  = 221
rolluikLinksGastBoven =  86
sensorRechtsGastBoven =  77
rolluikRechtsGastBoven=  81

--GastenVerblijfBeneden
deurGastBenVoor        =    273
deurGastBenAchter     = 336

--Serre
verlSerre2x           = 240
verlSerre1x           = 242
deurSerre             = 347
--Rond om het huis
verlTuin              =    40

--

-- Don't forget to declare triggers from devices in the header!!!
if dofile and not _EMULATED then _EMBEDDED={name="EventRunner", id=20} dofile("HC2.lua") end

_version,_fix = "2.0","B28"  -- Apr 27, 2019  

--[[
-- EventRunner. Event based scheduler/device trigger handler
-- Copyright 2019 Jan Gabrielsson. All Rights Reserved.
-- Email: [email protected]
-- Email: [email protected]
--]]

_sceneName   = "Demo"      -- Set to scene/script name
_homeTable   = "devicemap" -- Name of your HomeTable variable (fibaro global)
_HueHubs     = {}          -- Hue bridges, Ex. {{name='Hue',user=_HueUserName,ip=_HueIP}}
_myNodeRed   = "http://192.168.1.50:1880/eventrunner" -- Ex. used for Event.postRemote(_myNodeRed,{type='test'})
--if dofile then dofile("credentials.lua") end -- To not accidently commit credentials to Github, or post at forum :-)
-- E.g. Hue user names, icloud passwords etc. HC2 credentials is set from HC2.lua, but can use same file.

-- debug flags for various subsystems...
_debugFlags = {
  post=true,invoke=false,triggers=true,dailys=false,rule=false,ruleTrue=false,hue=false,msgTime=false,
  fcall=true, fglobal=false, fget=false, fother=true
}
---------------- Here you place rules and user code, called once at startup --------------------
function main()
  local rule,define = Rule.eval, Util.defvar

  HT =
  {
    dev =
    { bedroom = {lamp = 88,motion = 99},
      phones = {bob = 121},
      kitchen = {lamp = 66, motion = 77}
    },
    other = "other"
  }

  if _EMULATED then -- Things to do when we run in emulated mode
    -- _System.speed(true) -- Set speeding
    -- _System.setRemote("devices",11) -- setup device 11 for remote access
  end

  --or read in "HomeTable"
  --local HT = type(_homeTable)=='number' and api.get("/scenes/".._homeTable).lua or fibaro:getGlobalValue(_homeTable)
  --HT = json.decode(HT)

  Util.defvars(HT.dev)            -- Make HomeTable defs available in EventScript
  Util.reverseMapDef(HT.dev)      -- Make HomeTable names available for logger

  rule("@@00:00:05 => f=!f; || f >> log('Ding!') || true >> log('Dong!')") -- example rule logging ding/dong every 10 second

  --if dofile then dofile("example_rules.lua") end     -- some more example rules to try out...
end -- main()
-------------------------------------
------------------------------------------------------------------------
  -- Trigger rules
--Test http
 -- rule("@15:10 => httpGet('http://192.168.1.101/data.json?heater=0&setpoint=167&thermostat=0')")
--  deurnaarSerre
 

 
  --Woonkamer
  --Gordijnen sluiten lux 60
    Rule.eval("lightSensorBuVoor:lux < 100 & 16:35..23:00 => curtainFront:close")  

    Rule.eval("lightSensorBuVoor:lux < 100 & wait(00:00:10) & 16:35..23:00 => curtainSideCar:close")  

    Rule.eval("lightSensorBuVoor:lux < 100 & wait(00:00:15) & 16:35..23:00 => curtainSideBicycle:close")  

    Rule.eval("lightSensorBuVoor:lux < 100 & wait(00:00:20) & 16:35..23:00 => curtainBack:close")  

    Rule.eval("lightSensorBuVoor:lux < 100 & wait(00:00:25) & 16:35..23:00 => curtainBackSide:close")  

  -- Rule.eval("curtainFront:isClose => wait(00:00:10); curtainSideCar:close")   
 -- Rule.eval("curtainFront:isClose => wait(00:00:15); curtainSideBicycle:close")  
--  Rule.eval("curtainFront:isClose => wait(00:00:20); curtainBack:close")
--  Rule.eval("curtainFront:isClose => wait(00:00:05); curtainBackSide:close")
--Gordijnen openen
  Rule.eval("lightSensorBuVoor:lux > 105  => curtainFront:open")
  Rule.eval("lightSensorBuVoor:lux > 105 => wait(00:00:10); curtainSideBicycle:open")   
  Rule.eval("lightSensorBuVoor:lux > 105 => wait(00:00:15); curtainSideCar:open")  --
  Rule.eval("lightSensorBuVoor:lux > 105 => wait(00:00:20); curtainBack:open")
  Rule.eval("lightSensorBuVoor:lux > 105 => wait(00:00:25); curtainBackSide:open")   

  --licht aan als gordijn dicht is
  Rule.eval("once(lightSensorBuVoor:lux < 150) => keukenPlintLed:on")  
 -- Rule.eval("once(lightSensorBuVoor:lux < 100) => verlEetkamerPlafond:on")  
 
  --TV

  Rule.eval("once(stekkerStoelSjaak:power > 3) => stekkerTV:on")
  Rule.eval("once(stekkerStoelArleta:power > 3) => stekkerTV:on")
  Rule.eval("once(stekkerTV:power < 20) => wait(00:10:00);stekkerTV:off")

  --TV aan >> Licht aan
  Rule.eval("stekkerTV:power > 100 & curtainFront:isClosed => verlEetkamerPlafond:on")

--Stoel
  Rule.eval("stekkerStoelSjaak:power > 3 & lightSensorBuVoor: lux <200 => {type='property', deviceID= hueKastRechtsSpot, propertyName='bri', value=50}, {type='property', deviceID=<hueKastRechtsSpot>, propertyName='sat', value=99}")
--   Rule.eval("once(stekkerStoelArleta:power > 3 & lightSensorBuVoor: lux <200 => (326, "pressButton", "1")")

--Voordeur open
  Rule.eval("once (lightSensorBuVoor:lux < 130) & doorFront:breached   => verlOverloop:on & verlHal:on & verlBeeldBuiten:on")

  Rule.eval("doorFront:safe  => wait(00:04:00); verlOverloop:off & verlHal:off & verlBeeldBuiten:off")
--Hal
  --licht
  Rule.eval("verlHal:isOn  => wait(00:03:30); verlHal:off")
  Rule.eval("verlOverloop:isOn  => wait(00:04:00); verlOverloop:off")

  --Overloop
  Rule.eval("{deurHfdSlpkmr, deurGastboven}:safe => {stekkerTrap, stekkerLedOverloop}:on ")
  Rule.eval("lightSensorBuVoor:lux < 350 & deurHfdSlpkmr:breached & deurGastboven:safe => stekkerTrap:off & stekkerLedOverloop:off ")
  Rule.eval("lightSensorBuVoor:lux < 350 & deurHfdSlpkmr:safe & deurGastboven:breached => stekkerTrap:off & stekkerLedOverloop:off ")

  --deur

  --deurbel
  Rule.eval("deurbel:value > 0  => verlHal:on & keukenPlintLed:on & verlEetkamerPlafond:on & wait(00:00:15);verlHal:off & keukenPlintLed:off & verlEetkamerPlafond:off")
  fibaro:call(sonosPlayer, "pressButton", "7");
  fibaro:call(sonosPlayer, "setSlider", 15, "70");

  setTimeout(function()
      fibaro:call(sonosPlayer, "setSlider", 15, "25");
    end, 2*60*1000)
  fibaro:debug("Sonos op lager volume na 2 minuten")


--Keuken
  Rule.eval("@(20:30) & motionSensorEetkamer:breached & luxSensorEetkamer:lux < 12 => keukenPlintLed:on")
  Rule.eval("@(20:30) & motionSensorEetkamer:safe  => wait(00:30:00); keukenPlintLed:off")

  Rule.eval("stekkerAfzuigpkap:power > 15  => keukenPlintLed:on")
 -- Rule.eval("stekkerAfzuigpkap:off => wait(00:20:00); keukenPlintLed:off")
  Rule.eval("@(17:30) => keukenPlintLed:on")
  Rule.eval("@(20:30) => keukenPlintLed:off")

  -- Boven Verdieping
--Hfdslpkmr
--  Rule.eval("once (lightSensorBuVoor:lux < 350) & deurHfdSlpkmr:isBreached => verlHfdSlpkmr:on ")
 Rule.eval("lightSensorBuVoor:lux < 350 & deurHfdSlpkmr:breached => verlHfdSlpkmr:on ")

  Rule.eval("verlHfdSlpkmr:isOn  => wait(00:15:00); verlHfdSlpkmr:off")

--GastenKamerBoven
  Rule.eval("once (lightSensorBuVoor:lux < 350) & deurGastboven:breached => verlTafel:on & verlOverloop:on & verlHal:on")
  Rule.eval("once (lightSensorBuVoor:lux < 350) & deurGastboven:safe => wait(00:05:00); verlTafel:off & verlOverloop:off & verlHal:off")

  Rule.eval("sensorLinksGastBoven:breached  =>  rolluikLinksGastBoven:stop")
  Rule.eval("sensorLinksGastBoven:breached  =>  rolluikRechtsGastBoven:stop")
  Rule.eval("@16:30 & sensorLinksGastBoven:safe & verlTafel:off & verlBed:off =>  rolluikRechtsGastBoven:open")
  Rule.eval("@16:30 & sensorLinksGastBoven:safe & verlTafel:isOff & verlBed:isOff =>  rolluikLinksGastBoven:open")

 

--  rule("$Dagdelen=='Morgen' => httpGet('http://192.168.1.101/data.json?heater=0&setpoint=167&thermostat=0')")
--  rule("motion:breached & once(05:00..08:00) => speak('Hallo en goede morgen!')") -- announce to first person breacing motion sensor in the morning...

--GastenVerblijfBeneden
  Rule.eval("once (lightSensorBuVoor:lux < 130) & deurGastBenVoor:isBreached   => verlBeeldBuiten:on")
  Rule.eval("deurGastBenVoor:isSafe  => wait(00:04:00); mverlBeeldBuiten:off")
  Rule.eval("once (lightSensorBuAchter:lux < 130) & deurGastBenAchter:isBreached   => verlBeeldBuiten:on")
  Rule.eval("deurGastBenAchter:isSafe  => wait(00:04:00); verlBeeldBuiten:off")

--Rondom het huis
  --Tuin achter
  --Fontein
  Rule.eval("once(stekkerFontein:isOn ) => wait(00:00:15); stekkerFontein:off & wait(00:00:15);stekkerFontein:on & wait(00:00:15); stekkerFontein:off & wait(00:00:15);stekkerFontein:on)")
Rule.eval("once(deurSerre:isClose ) => stekkerFontein:off")

    
  Rule.eval("once (lightSensorBuAchter:lux < 15) & bewegingSensorAchter:isBreached => verlTuin:on")
  Rule.eval("verlTuin:isOn  => wait(00:15:00); verlTuin:off")

--   Rule.eval("once (myLightSensorBuAchter:lux < 4) & GastBeneden;isOff & bewegingSensorAchter:isBreached &=> VerlTuin:on & telefoonSjaak, "sendDefinedPushNotification", "225"")
--<<<<<<<<<<<<<<<<<<<<<<send push notification>>>>>>>>>>>>>>   

 

  -- Buitenverlichting aan
--  Rule.eval("once(lightSensorBuAchter:lux < 4) => myVerlFietsenhok:on")
--  Rule.eval("verlFietsenhok:isOn => wait(00:00:05); myVerlVlag:on")
--  Rule.eval("verlFietsenhok:isOn, GastBeneden:isOff => wait(00:00:10); verlGastAchterdeur:on")
--  Rule.eval("verlFietsenhok:isOn, GastBeneden:isOff => wait(00:00:10); verlBeeldBuiten:on")
--  Rule.eval("verlFietsenhok:isOn, GastBeneden:isOff => wait(00:00:15); verlSerre1x:on")
 
 
    
    Rule.eval("@{sunset+00:50} => verlFietsenhok:on")
    Rule.eval("@{sunset+00:50} => wait(00:00:05); verlVlag:on")
    Rule.eval("@{sunset+00:50} &  GastBeneden:isOff => wait(00:00:10); verlGastAchterdeur:on")
    Rule.eval("@{sunset+00:50} &  GastBeneden:isOff => wait(00:00:10); verlBeeldBuiten:on")
    Rule.eval("@{sunset+00:50} &  GastBoven:isOff => wait(00:00:15); verlSerre1x:on")

 
 
 
 
 
 
 
  --Buitenverlichting uit
     
  Rule.eval("once (lightSensorBuVoor:lux > 4) => verlFietsenhok:off")
  Rule.eval("@{sunrise-00:50} =>  wait(00:00:05); verlVlag:off")
  Rule.eval("@{sunrise-00:50} =>  wait(00:00:10); verlGastAchterdeur:off")
  Rule.eval("@{sunrise-00:50} =>  wait(00:00:15); verlBeeldBuiten:off")
  Rule.eval("@{sunrise-00:50} =>  wait(00:00:20); verlSerre1x")
  --Vlagverlichting uit----------
  Rule.eval("@23:15 => verlVlag:off")
  --Zolder
  --Afzuiging


  -- Simulated triggers
  if _EMULATED then
    rule("wait(00:10); stekkerStoelSjaak:power=5") -- set to 5 after 10min
    rule("wait(00:11); stekkerStoelSjaak:power=0") -- off after 11min
    rule("wait(t/16:00); lightSensorBuVoor:value=100") -- set sensor value to 100 at 16:00 today
  end
 
--end -- main()

 

  • Topic Author
  • Posted
    4 minutes ago, Sjakie said:

    Here it is:

     

    You still have the main() that comes with the scene in there and you define your rules outside "main() ... end"

    You see that you had to comment out the 'end' after your rules to make it compile? That's because you had moved your rules outside the main() function.

    Please login or register to see this code.

    change it to this and add an 'end' after your rules

    Please login or register to see this code.

     

    Posted

    okay done and running I am very sory

  • Topic Author
  • Posted (edited)
    41 minutes ago, Sjakie said:

    Here it is:

     

    Quickly  looked through your code and have some comments:

    Please login or register to see this code.

    You have not setup Hue for ER yet?, because the rule does not work. If setup correctly the rule would look like

    Please login or register to see this code.

    It's easy to press  a VD button from a rule

    Please login or register to see this code.

    This part

    Please login or register to see this code.

    At startup this will press button 7 on the sonos VD and then set the slider 15 value to 70.

    Then it will wait 2 minutes and set the slider value to 25. 

    This only happens once, and when the scene starts up. Is that the intention?

     

    You can easily do that with a rule... if you use the "ID:" name of the slider instead of the number. I use "Slider1" here, but your label may have another "ID:" name.

    (rules without a "=>" are just expression that are run when evaluated)

    Please login or register to see this code.

     

    Edited by jgab
  • Topic Author
  • Posted

    And you have a lot of tests against :lux and :power that I would wrap in a once() so you don't get multiple trigger every time the lux/power value is under or over the value you test against.

    Ex.

    Please login or register to see this code.

    will trigger every time lightSensorBuVoor:lux changes value and is greater than 105.

    Please login or register to see this code.

    If this rule trigger it will require that the value is lower than 106 before triggering on a value over 105 again.

    Posted

    Thanks Jan,

    Here I had Rule.eval("(once (stekkerTV:power < 15) => wait(00:10:00);stekkerTV:off") result in switching off TV every 10 minutes even if he is on and consuming 300 Watt(Home cinema)

    Modified in>>>> Rule.eval("stekkerTV:power < 15 => wait(00:20:00);stekkerTV:off") switch of I dont know becaus TV is still on

    This I dont understand

  • Topic Author
  • Posted
    3 minutes ago, Sjakie said:

    Thanks Jan,

    Here I had Rule.eval("(once (stekkerTV:power < 15) => wait(00:10:00);stekkerTV:off") result in switching off TV every 10 minutes even if he is on and consuming 300 Watt(Home cinema)

    Modified in>>>> Rule.eval("stekkerTV:power < 15 => wait(00:20:00);stekkerTV:off") switch of I dont know becaus TV is still on

    This I dont understand

     

    The syntax is strange as you have everything with paranthesis in your first example.

    It's risky to test if a value is true and then wait 10min and then do something with the assumption that the test is still true. There is a construction 'for' that is used to make sure a test is true for a certain amount of time.

    Please login or register to see this code.

    If the TV is off when you start the scene, the rule will not immediately get a trigger as the power is not changing. A way to make trigger rules run when the scene start up is to add .start() like I have done in the example. Then the rule will always run at startup and detect that the power is less than 15 and start the timer resulting in the power being cut after 10min. However, if someone turns on the TV during these 10min the timer will automatically cancel and nothing will happen.

     

    Posted

    Thanks Jan,

    I understand while I am working on the scene it will not act as I when I am doing nothing.

    Posted
    3 hours ago, jgab said:

     

    Ok, there is a new version B28 where you can set _STARTONTRIGGER=true

    ...experimental, let me know how it works.

     

    Thanks, scene was started, it's OK

    but there is no reaction on rules where is used "subscribe" from other scenes (I'm using latest version from github)

     

  • Topic Author
  • Posted (edited)
    10 minutes ago, petrkl12 said:

     

    Thanks, scene was started, it's OK

    but there is no reaction on rules where is used "subscribe" from other scenes (I'm using latest version from github)

     

     

    A publisher will never publish to a stopped scene (the publisher check that the subscriber is running before posting)

    When the subscriber starts up it with will start to receive the events again

    Edited by jgab
    Posted

    I know but it doesn't work even after scene started  ...

  • Topic Author
  • Posted (edited)
    11 minutes ago, petrkl12 said:

    I know but it doesn't work even after scene started  ...

    Strange, I have 2 publisher and subscriber scenes on the HC2 with the latest version and they behave correct both with _STARTONTRIGGER=false and _STARTONTRIGGER=true.

    If you set _debugFlags.triggers=true do you see the incoming triggers/events ?

     

    You run on HC2 or emulated?

    Edited by jgab
    Posted

    I'm running scene directly on HC2 - 

     

    Some interesting behavior: if scene is started manually - it works but if scene started via trigger it doesn't work for rules with subscriber (_STARTONTRIGGER=true)

     

    with _STARTONTRIGGER=false - it works OK

     

  • Topic Author
  • Posted
    32 minutes ago, petrkl12 said:

    I'm running scene directly on HC2 - 

     

    Some interesting behavior: if scene is started manually - it works but if scene started via trigger it doesn't work for rules with subscriber (_STARTONTRIGGER=true)

     

    with _STARTONTRIGGER=false - it works OK

     

    Ok, it turned out that the pub/sub routine needed 'autostart' or 'other' to start subscribing. However, now a scene can be started by any type of event.

    The way I solved it is that if the scene is started by any other type of event (like a publish) it will post an additional  'other' event so that rules that want to know if the the scene has started will be triggered.

    Pushed "2.0","B31" 

    Posted

    Super, It works!

    Posted

    @jgab

     

    I have one suggestion - could be possible to develop function for sharing 

    Please login or register to see this code.

    with other scenes via publish/subscribe ?

     

    so it means in one scene I want to define functions ie. for sonos and in other scenes I want to use new function for sonos as a standard ER rules.

    Posted

    jgab, You mentioned earlier:" I'm not familiar with the Sonos VD you use so I may have done something wrong. I tend to run Sonos and integration towards other systems with Node-red.  "

    Is this only to comment wich rules are executed or can you also do  voice command?

    without using Alexa?

     

  • Topic Author
  • Posted

    With Alexa you can do (limited) voice commands. Here is @jompa68 steering his TV with EventRunner and node-red,Alexa

    I use node-red to get some Alexa commands, play sonos voice messages using alexa text-to-speech, etc 

    Main description here. I run the node-red server on a raspberry-pi.

     

    Here is the updated flow with local Alexa input

     

    38 minutes ago, petrkl12 said:

    @jgab

     

    I have one suggestion - could be possible to develop function for sharing 

    Please login or register to see this code.

    with other scenes via publish/subscribe ?

     

    so it means in one scene I want to define functions ie. for sonos and in other scenes I want to use new function for sonos as a standard ER rules.

     

    That should be doable, let me think about it...

    Posted

    jgab, good morning

    Thanks for explanation. I was thinking to get in the direction of voice control for my wife, she doest understand technical stuf.

    I hope it will work much better as the Alexa on the HC2 I have tried but send the Alexa back because I was not satisfied with the whole installation.

    Can I ask is it nice to voice control your house? Does it recognize your command easily or do you have to say it several times?

    So I need Raspberry Pi with node red installed on it, Alexa Echo and if I want TV Harmony hub.

    Can I use Raspberry Pi simultaneous as  Nas?

    Thanks in advance

     

    Posted
    34 minutes ago, Sjakie said:

    So I need Raspberry Pi with node red installed on it,

    I can recommend run Proxmox VE , it is a open source virtualization platform. I have setup 3 different linux containers with different purposes, one of the containers is where i have installed node-red.

     

    Please login or register to see this image.

    /monthly_2019_04/1095135142_Skrmavbild2019-04-28kl_08_43_16.png.4498cc8b8b8ded06f8a9e8b275a72a15.png" alt="1095135142_Skrmavbild2019-04-28kl_08_43_16.png.4498cc8b8b8ded06f8a9e8b275a72a15.png" />

     

    I run backup every night to my nas so it easy to recover if needed.

     

     

    Join the conversation

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

    Guest
    Reply to this topic...

    ×   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...