Created At

Oct 22, 2017

Last Update

Nov 02, 2017

Platforms

HC 2

Views

6084

Download

207

Forum Topic

This is a very simple virtual device that is compatible with the fine Smart Lights scene provided by stevenvd.  It also borrows from the contributions of some leading lights of this community as referenced in the code. Thanks to all - .stevenvd, Robmac, Krikroff, Shad, Dalle1985, Jompa68 and many other forum members.

 

It is a simple VD that presents and allows the manual change of the global 'state' variables used by Smart Lights:  presentState, TimeOfDay and sleepState.

 

 

I have this VD running in a section called House.  I find it very helpful to see and  - at times - manually adjust the state variables.  Otherwise the state variables are managed by a set of scenes:

 

You will find more sophisticated versions within the forum as well but this is a good starting point for anyone begining to automate using some common techniques, global variables, scenes and VDs found on the forum.

 

TimeOfDay (Morning, Day, Evening, Night)

These are all managed via block scenes:

  • EventSunRise -setting "Morning" on sunrise
  • EventSunSet - for "Evening" on sunset
  • EventDayTime -  sets "Day" at fixed time (09:00) for me
  • EventNightTime -  sets "Night" at fixed time (21:00) for me 

 

sleepState (Sleeping Waking up, Awake, Going to sleep)

This is managed by a set of block scenes and also be other VD.  For example, in the master bedroom I have a 'Sleep Timer' virtual device that acts as a 'reverse' alarm clock dimming lights and volume on Sonos after preset or custom sleep 'delay'.  In this sleepState is set to "Going to sleep" at start of the process and switched to "Sleeping" when timer expires.

 

  • EventHouseWakingUp - simple time based trigger  to set "Waking Up"
  • EventHouseAwake(Default) - simple time based trigger to set "Awake" at 09:00
  • EventHouseSleeping - simple time based trigger to set "Going to sleeping" at a  default time

 

Other scenes or devices could also change this state - it is simple at present - but I use as trigger for other actions.

 

presentState (Home, Away, Holiday)

This is currently managed by this House Status VD only but could easily be trigger in other ways.

 

guestMode (Family, Guests)

This is not used in SmartLights scene by stevenvd.  It is currently managed manually through this House Status VD only.

 

The virtual device code follows a common pattern in each button that cycles through the defined domain values for each state and updates the UI.  You will see a identical code snippet in each button - behaviours are controlled through parameters called managedGlobal, uiVariable and state.  This makes it easy to add extra buttons for other global variables if you wish.

 

-- standard headers
local version = "0.3"
local contributors = "stevenvd, Robmac, Krikroff, Shad, Dalle1985, Jompa68 and many other forum members."
local debug = true
local thisdevice = fibaro:getSelfId();

-- helper functions

Debug = function (debug,color, message )
  if (debug) then
  	fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); 
  end
end

-- start up

Debug( true,"orange", "House Status VD - assembled by ipsofacto 2015" );
Debug( true,"orange", "Recognition and thanks to inspiration, snippets, techniques from " ..contributors)
Debug( true,"orange", "Version: "..version);

-- parameters for this code

local managedGlobal = "GuestMode"
local uiVariable = "ui.lblGuestMode.value"
local state = {"Family","Guests"}

Debug(debug,"lightgreen","managedGlobal: "..managedGlobal.." presented in "..uiVariable);

-- main: cycle states

local managedState = fibaro:getGlobalValue(managedGlobal)
Debug(true,"blue",managedGlobal.." is "..managedState) 

-- each press toggle through available states

for i= 1, #state do
	Debug(debug,"lightgreen","State "..i.." is "..state[i] )

  	if state[i] == managedState then
    	Debug(debug,"lightgreen","i="..i.." state[i]="..state[i])
      if i == #state then 
      		managedState = state[1]
      	else
      		managedState = state[i+1]
      	end
    	Debug(true,"blue","New "..managedGlobal.." is "..managedState)
  	break
  	end
end  

-- finally ensure UI and global are up to date

fibaro:setGlobal(managedGlobal,managedState)
fibaro:call(thisdevice,"setProperty",uiVariable,managedState);

The main loop is a simple construct to create a summary sentence for the compact/expanded VD display form - it shows status details as best it can given available screen real-estate.  For example,  "It is Night and the house is Awake. (Home with Family)."

 

 

2 Comments,  Want to add comment please login
Aff5d68fa97a547900373a72589861ea

..and why on earth am I 'user unnamed' when I logged in here with my creds? :D

Aff5d68fa97a547900373a72589861ea

ok, so I am a beginner. I can see the d/l is a zip file with some icons and a .vfib file. The latter I can import as a VD, as instructed. How do I add the icons? one by one, selecting them in the new virtual device as change icon? I tried uploading the zip file but it did not work. Thanks

Load more comments