Single Scene / Event model by @jgab
Jag har blivit "frälst" av EventRunner. Håller på att lära mig och försöka att förstå. Just nu har jag lagt in några lampor som skall tändas och släckas, funkar bra. Men [DEBUG] info rader blir trunkeradeoch jag har inte hittat var man kan ändra längden.
Ok, jag ska fixa så att man kan definiera längden själv. Har du andra frågor/funderingar så supportar jag gärna i det här forumet också.
Ja, det är alltså bara texten i loggen när regeln definieras som trunkeras, själva regeln definieras i sin helhet.
/J
Ja, det är alltså bara texten i loggen när regeln definieras som trunkeras, själva regeln definieras i sin helhet.
/J
Last edited by jang on 29 Oct 2018, 16:34, edited 2 times in total.
Nu är det inte jag som gjort EventRunner, det är @jang/@jgab men jag hjälper gärna till också.
Här kommer lite exempel vad som kan göras med EventRunner.
Nu finns även stöd för att skicka data till en node-red server.
Nu finns även stöd för att skicka data till en node-red server.
Code: Select all
_version = "1.7" -- fix6,Jan 3, 2019
--[[
-- EventRunner. Event based scheduler/device trigger handler
-- Copyright 2018 Jan Gabrielsson. All Rights Reserved.
-- Email: jan@gabrielsson.com
--]]
_sceneName = "Larssons SuperHouse - Cron" -- Set to scene/script name
_deviceTable = "jL_HomeTable" -- Name of json struct with configuration data (i.e. "HomeTable")
ruleLogLength = 60
_debugFlags = { post=true,node_red=true,invoke=false,triggers=false,dailys=false,timers=false,rule=false,ruleTrue=false,fibaro=false,fibaroGet=false,fibaroSet=false,sysTimers=false }
_GUI = true
_SPEEDTIME = 24*36
HueIP = "192.168.1.68" -- set to Hue bridge
HueUserName = "xxxxxxx" -- set to Hue user name
NodeRed=true -- true, will start listener from node-red server(s)
NodeRed = "http://192.168.1.104:1880/eventrunner"
-- If running offline we need our own setTimeout and net.HTTPClient() and other fibaro funs...
if dofile then dofile("EventRunnerDebug.lua") require('mobdebug').coro() end
---------------- Here you place rules and user code, called once --------------------
function main()
local devs = json.decode(fibaro:getGlobalValue(_deviceTable))
Util.defvars(devs)
Util.reverseMapDef(devs)
local rule, define = Rule.eval, Util.defvar
local function prop(id,state,prop) return {type='property', deviceID=id, propertyName=prop, value=state} end
for id,name in pairs(devs.hueMap) do Hue.define(name,nil,tonumber(id)) end
rule("phoneToNotify={iOS.iPhoneXJonny,iOS.MonasiPhoneX}")
-- SECTIONS
Event.SECTION='Winter'
-- entre
rule("@sunset-00:30 => VD.DownlightsSonoff:btn=1;log('Tänder entre lampor')")
rule("@sunrise+00:30 => VD.DownlightsSonoff:btn=2;log('Släcker entre lampor')")
-- ute vägg
rule("hueGroup1 = {hue.huevagg.spot1,hue.huevagg.spot2,hue.huevagg.spot3,hue.huevagg.spot4}")
rule("@sunset-00:30 => hueGroup1:on; log('tänd hue vägg lampor')")
rule("@sunrise+00:30 => hueGroup1:off; log('Släcker hue vägg lampor')")
-- altan
rule("@sunset-00:30 => VD.SonoffAltan:btn=1;log('Tänder altan spotlights')")
rule("@sunrise+00:30 => VD.SonoffAltan:btn=2;log('Släcker altan spotlights')")
-- garage
rule("@sunset-00:30 => Garaget.Lampa:on;log('Tänder garage lampa')")
rule("@sunrise+00:30 => Garaget.Lampa:off;log('Släcker garage lampa')")
Event.SECTION='Summer'
-- entre
rule("@sunset-00:10 => VD.DownlightsSonoff:btn=1;log('Tänder entre lampor')")
rule("@sunrise+00:10 => VD.DownlightsSonoff:btn=2;log('Släcker entre lampor')")
-- ute vägg
rule("hueGroup1 = {hue.huevagg.spot1,hue.huevagg.spot2,hue.huevagg.spot3,hue.huevagg.spot4}")
rule("@sunset-00:10 => hueGroup1:on; log('tänd hue vägg lampor')")
rule("@sunrise+00:10 => hueGroup1:off; log('Släcker hue vägg lampor')")
-- altan
rule("@sunset-00:10 => VD.SonoffAltan:btn=1;log('Tänder altan spotlights')")
rule("@sunrise => VD.SonoffAltan:btn=2;log('Släcker altan spotlights')")
-- garage
rule("@sunset-00:10 => Garaget.Lampa:on;log('Tänder garage lampa')")
rule("@sunrise => Garaget.Lampa:off;log('Släcker garage lampa')")
Event.SECTION=nil
rule([[@00:00 || #autostart =>
|| month('oct-apr') >> enable('Winter');disable('Summer')
|| month('may-sep') >> enable('Summer'); disable('Winter')
]])
-- BANKHOLIDAYS
_BankDays = json.decode(fibaro:getGlobalValue("BankHol_ThisYear"))
BankDays={}
for k,v in pairs(_BankDays) do
BankDays[osDate('%x',v)]=k -- remap table from <holiday>=<epoch> to <month/day/year>=<holiday>
end
function bankholiday() return BankDays[osDate('%x')] end
-- SCHEDULED TASKS
rule("@23:59 => $BankHoliday=0") -- Reset bankholiday variable
rule("@00:06 => || bankholiday() >> $BankHoliday=1;log('It is a bank holiday today (%s)',bankholiday())")
rule("@@00:01 => scene.AlarmClockMain:start")
rule("@03:00 => scene.Bankholiday:start")
rule("@@00:01 => VD.Hoforstemperaturnu:btn=1")
rule("@03:00 & wday('sat-sun') => $AlarmClockDays1='Weekends';$AlarmClockTime1='07:30';$AlarmClockDays2='Weekends';$AlarmClockTime2='07:30';log('Alarmklocka: %s %s', $AlarmClockTime1, $AlarmClockDays1,) ")
rule("@03:00 & wday('mon-fri') & $BankHoliday==1 | $Holiday==1 => $AlarmClockDays1='Weekdays';$AlarmClockTime1='07:30';$AlarmClockDays2='Weekdays';$AlarmClockTime2='07:30';log('Alarmklocka: %s %s', $AlarmClockTime1, $AlarmClockDays1,) ")
rule("@03:00 & wday('mon-fri') & $BankHoliday==0 => $AlarmClockDays1='Weekdays';$AlarmClockTime1='05:00';log('Alarmklocka: %s %s', $AlarmClockTime1, $AlarmClockDays1,) ")
rule("@03:00 & wday('mon-fri') & $BankHoliday==0 => $AlarmClockDays2='Weekdays';$AlarmClockTime2='07:00';log('Alarmklocka: %s %s', $AlarmClockTime2, $AlarmClockDays2,) ")
rule("@17:00 & wday('sun') & wnum % 2 == 0 => remote(NodeRed,#speak{data='Dax att vattna blommorna', volume='70'});iOS.MonasiPhoneX:msg=log('Mona, det är dax att vattna blommorna!')")
rule("@09:00 & wday('mon') & wnum % 2 == 1 => remote(NodeRed,#speak{data='Dax att vattna blommorna', volume='70'});iOS.MonasiPhoneX:msg=log('Mona, kom du ihåg att vattna igår?!')")
rule("@09:00 & wday('wed') & wnum % 2 == 1 => scene.SMsgHv12:start={'Vattna blommorna idag','telegram'}")
rule("@17:00 & wday('wed') & wnum % 2 == 1 => remote(NodeRed,#speak{data='Dax att vattna blommorna', volume='70'});iOS.MonasiPhoneX:msg=log('Kom ihåg att ställa fram soptunnorna')")
rule("@17:00 & wday('wed') & wnum % 2 == 1 => scene.SMsgHv12:start={'Soptunnorna ska fram','telegram'}")
-- iOSLocation
locations = {}
numberOfPeople = 2
homeFlag = nil
rule("#autostart => 456:start=#getLocations")
rule("#location{user='$user',place='$place'} => log('User:%s place:%s',user, place)")
rule("#presence{state='home',who='$who'} => log('%s at home',who)")
rule("#location{user='Jonny', place='Home'} => $UHASTimeOfDay~='Dag' & VD.taklampaSonoff:btn=1")
rule("#location{user='Mona', place='Home'} => $UHASTimeOfDay~='Dag' & VD.taklampaSonoff:btn=1")
rule("for(00:15,label(VD.taklampaSonoff,'Label1')=='ON') => VD.taklampaSonoff:btn=2")
-- Event from iOSLocation service
rule([[#location{user='$user', place='$place'} =>
locations[user]=place;
post(#checkLocations)]])
Event.event({type='checkLocations'},
function(event)
local home,c = false,0
local who = {}
for w,p in pairs(locations) do
c=c+1; if p == 'Home' then home=true; who[#who+1]=w end
end
if home and home ~= homeFlag then
homeFlag = true
Event.post({type='presence', state='home', who=table.concat(who,',')})
elseif c == numberOfPeople then
if not home and homeFlag ~= false then
homeFlag = false
Event.post({type='presence', state='allaway'})
end
end
end)
-- WC, uses a local flag (inBathroom)
rule("#autostart => Wc.Fan:off")
rule("for(00:10,Wc.Sensor:safe & Wc.doorsensor:value) => Wc.Fan:off")
rule("Wc.Sensor:breached => Wc.doorsensor:safe & inBathroom=true ; Wc.Fan:on")
rule("Wc.doorsensor:breached => inBathroom=false")
rule("Wc.doorsensor:safe & Wc.Sensor:last<=3 => inBathroom=true")
-- KÖKET
rule([[for(02:30,Kok.Vattendiskmaskin:isOn) => Kok.Vattendiskmaskin:off; iOS.iPhoneXJonny:msg=log('Stänger av vattnet till diskmaskin')]]) -- turn off water to dishwasher
rule([[for(00:45,893:isOn) => remote(NodeRed,#speak{data='Stänger nu av kaffebryggaren', volume='70'});iOS.iPhoneXJonny:msg=log('Stänger nu av timern till kaffebryggaren %s',osdate('%X'))]])
rule("Kok.Diskmaskin:power>0.5 => Kok.Vattendiskmaskin:on;log('Öppnar vattenkran till diskmaskin')")
rule("$UHASDarkness=='Mörkt' & $UHASPresentState=='Hemma' & $VSL_sleep_5=='Vaken' => post(#kokOn)")
rule("775:lux < 20 & $UHASPresentState=='Hemma' & $VSL_sleep_5=='Vaken' => post(#kokOn)")
rule("$VSL_sleep_5=='Sover' => post(#kokOff)")
rule("$UHASPresentState=='Borta' => post(#kokOff)")
rule("$UHASDarkness=='Dagsljus' & 775 > 20 => post(#kokOff)")
rule("#kokOn => log('Tänder lampor i köket');hue.huekok.lampastora:on;hue.huekok.lampalilla:on;VD.KksbnkenSonoff:btn=1")
rule("#kokOff => log('Släcker lampor i köket');hue.huekok.lampastora:off;hue.huekok.lampalilla:off;VD.KksbnkenSonoff:btn=2")
-- VARDAGSRUM
rule("$UHASDarkness=='Mörkt' & $UHASPresentState=='Hemma' & $VSL_sleep_4=='Vaken' => post(#vardagsrumOn)")
rule("802:lux < 14 & $UHASPresentState=='Hemma' & $VSL_sleep_4=='Vaken' => post(#vardagsrumOn)")
rule("$VSL_sleep_4=='Sover' => post(#vardagsrumOff)")
rule("$UHASPresentState=='Borta' => post(#vardagsrumOff)")
rule("$UHASDarkness=='Dagsljus' & 802:lux > 14 => post(#vardagsrumOff)")
rule("#vardagsrumOn => log('Tänder lampor i vardagsrum');hue.huevrum.lampatv:on;hue.huevrum.lampaaltan:on;vardagsrum.LedlistTV:on;vardagsrum.Kruka:on;VD.BokhyllanSonoff:btn=1")
rule("#vardagsrumOff => log('Släcker lampor i vardagsrum');hue.huevrum.lampatv:off;hue.huevrum.lampaaltan:off;vardagsrum.LedlistTV:off;vardagsrum.Kruka:off;VD.BokhyllanSonoff:btn=2")
rule("$UHASCinemaState=='Ja' => remote(NodeRed,#speak{data='Nu blir det filmtajm', volume='70'});post(#cinemaOn)")
rule("$UHASCinemaState=='Nej' => post(#cinemaOff)")
rule("#cinemaOn => hue.huevrum.lampatv:value=10;hue.huevrum.lampaaltan:value=10;vardagsrum.Kruka:off")
rule("#cinemaOff => hue.huevrum.lampatv:value=99;hue.huevrum.lampaaltan:value=99;vardagsrum.Kruka:on")
rule([[
once(789:temp>25) =>
918:msg=log('Varmt i v-rum: %s',789:temp);926:on
]])
rule([[
once(789:temp<25) =>
918:msg=log('Temperatur: %s',789:temp);926:off
]])
-- HALL
rule("hallLights = {Hall.Taklampa}")
rule("hallSensors = {930}")
rule("for(00:05,hallSensors:safe) & hallLights:isOn => post(#lightLeftOn{room='Hall'}); repeat()")
rule("837:breached & 930:safe & $UHASDarkness=='Mörkt' & $UHASSleepState=='Vaken' => hallLights:on")
-- KÄLLAREN
rule("kallareLights = {767}")
rule("kallareSensors = {Storarummet.Kllardrr,762}")
rule("for(00:10,kallareSensors:safe) & kallareLights:isOn => post(#lightLeftOn{room='Källare'}); repeat()")
rule("Storarummet.Kllardrr:breached => 767:on")
-- GÄSTRUM
rule("$UHASDarkness=='Mörkt' => Gastrum.Fnster:on ")
rule("$VSL_sleep_152=='Sover' => Gastrum.Fnster:off")
-- SOVRUM
rule("$UHASDarkness=='Mörkt' => Sovrum.sovrumfnsterlampa:on ")
rule("$VSL_sleep_15=='Sover' => Sovrum.sovrumfnsterlampa:off;VD.S20_Sonoff_Socket1:btn=1;VD.S20_Sonoff_Socket3:btn=1")
rule("for(00:20,label(VD.S20_Sonoff_Socket1,'Label1')=='ON') => VD.S20_Sonoff_Socket1:btn=2")
rule("for(00:20,label(VD.S20_Sonoff_Socket3,'Label1')=='ON') => VD.S20_Sonoff_Socket3:btn=2")
rule("Sovrum.Swipe:central.keyId=='1' => VD.S20_Sonoff_Socket1:btn=1")
rule("Sovrum.Swipe:central.keyId=='2' => VD.S20_Sonoff_Socket1:btn=2")
-- DÖRR/FÖNSTER SENSORER
rule("sensors={831,834,822,825,837}")
rule("for(00:10,sensors:breached) & month('nov-mar') => d=env.event.deviceID; iOS.iPhoneXJonny:msg=log('Fönster %s i rum %s är öppet',d:name,d:roomName)")
rule("@23:30 & $UHASSleepState=='Vaken' => $UHASSleepState='Sover'")
rule("$UHASSleepState=='Sover' => remote(NodeRed,#speak{data='Släcker huset, godnatt och sovgott', volume='70'})")
-- POSTLÅDAN
local postIn = false
local postFetched = false
rule("904:breached => postIn=true; iOS.iPhoneXJonny:msg=log('Det finns post i postlådan')")
rule("904:breached & #presence{state='home'} => remote(NodeRed,#speak{data='Posten har varit här', volume='70'})")
rule("901:breached => postFetched=true;postIn=false; iOS.iPhoneXJonny:msg=log('Postlådan är tömd')")
-- SLÄCK HUSET NÄR DET INGEN ÄR HEMMA LÄNGRE
rule("#presence{state='allaway'} & $UHASGuestState == 'Nej' => log('Ingen hemma, släcker huset')")
-- EVENT LIGHT LEFT ON
rule([[#lightLeftOn{room='$room'} =>
|| room == "Hall" >> hallLights:off
|| room == "Källare" >> kallareLights:off;;
log('Event lightLeftOn in %s',room )
]])
-- PRESENCE SIMULATOR
rule("lampSim={Hall.Taklampa, Kok.Taklampa, Wc.tak, hue.huevrum.lampatv,hue.huevrum.lampaaltan,hue.huekok.lampastora,hue.huekok.lampalilla}")
rule("@@rnd(00:05,00:55) & #presence{state='allaway'} & 06:00..00:15 => lampSim[rnd(1,size(lampSim))]:toggle")
--dofile("example_rules.lua") -- some example rules to try out...
end -- main()