I feel like I'm blind because I don't see this but is it possible as an event step, to save the current device state to a variable? So that I can have it change to On for example, and then return to like 25% or whatever it was at? Just wondering if this can be done with the web interface or if it needs scripting. Thanks!
Announcement
Collapse
No announcement yet.
Save device state to a variable?
Collapse
X
-
... and I have just written a script to save and restore states.
The whole idea behind the script is that a wife of another forum user wanted HomeSeer to remember the light setting as it was right now, so she later could just restore them after they had been turned off.
Code:Sub Main(ByVal not_used As Object) 'By Moskus, August 2015 'Set up a new config. 'Specify devices between the brackets below (comma separated): Dim devices() As Integer = {342, 872, 873} 'Specify a configuration name. This is used when calling "Save" and "Load" later. Dim config_name As String = "Bedroom" 'Creating initial ini file and store it in a list Dim lst As New System.Collections.Generic.List(Of DeviceState) For Each d As Integer In devices Dim dS As New DeviceState dS.deviceRef = d dS.deviceValue = hs.DeviceValueEx(d) lst.Add(dS) Next 'Write the list to file SaveToFile(config_name, lst) End Sub Sub Save(ByVal config_name As String) 'Get the device list Dim lst As System.Collections.Generic.List(Of DeviceState) = LoadFromFile(config_name) 'Get the current device values for each device For Each d As DeviceState In lst d.deviceValue = hs.DeviceValueEx(d.deviceRef) Next 'Store the list SaveToFile(config_name, lst) End Sub Sub Load(ByVal config_name As String) 'Get the device list Dim lst As System.Collections.Generic.List(Of DeviceState) = LoadFromFile(config_name) For Each d As DeviceState In lst 'Find the correct CAPI based on device value... Dim CAPIcontrol As HomeSeerAPI.CAPIControl = Nothing For Each cc As HomeSeerAPI.CAPIControl In hs.CAPIGetControl(d.deviceRef) If d.deviceValue = cc.ControlValue Then CAPIcontrol = cc Exit For End If Next '... And execute it hs.CAPIControlHandler(CAPIcontrol) Next End Sub Function LoadFromFile(ByVal config_name As String) As System.Collections.Generic.List(Of DeviceState) Dim lst As New System.Collections.Generic.List(Of DeviceState) Dim filename As String = "DeviceState_" & config_name & ".ini" Dim lines() As String = hs.GetINISectionEx("Devices", filename) For Each line As String In lines Dim deviceRef As Integer = line.Split("=")(0).Trim Dim deviceValue As Double = line.Split("=")(1).Trim lst.Add(New DeviceState(deviceRef, deviceValue)) Next Return lst End Function Sub SaveToFile(ByVal config_name As String, ByVal stateList As System.Collections.Generic.List(Of DeviceState)) Dim filename As String = "DeviceState_" & config_name & ".ini" For Each d As DeviceState In stateList hs.SaveINISetting("Devices", d.deviceRef, d.deviceValue, filename) Next End Sub <Serializable> Public Class DeviceState Public Property deviceRef As Integer Public Property deviceValue As Double Public Sub New() End Sub Public Sub New(ByVal _deviceRef As Integer, ByVal _deviceValue As Double) Me.deviceRef = _deviceRef Me.deviceValue = _deviceValue End Sub End Class
There are two ways of setting it up. 1) You could either edit the "Main" sub (change the parameters "config_name" and "devices") and run the Main sub, OR 2) you could just make the ini-file yourself. The contents should be on this format:
Code:[Devices] deviceReference1=deviceValue1 deviceReference2=deviceValue2 deviceReference3=deviceValue3 ... and so on
Code:[Devices] 342=53 872=25 873=39
(... but use Load instead of Save)
This makes a quick and dirty way to create basic scenes. The script only reads the device value for a device and sets the device to that value, so you could easily create different scenes like "Bedroom-Morning", "Bedroom-Sexytime", "Bedroom-Night", "Bedroom-Off", etc.HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
Running on Windows 10 (64) virtualized on ESXi (Fujitsu Primergy TX150 S8).
WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample
Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!
Comment
-
Originally posted by mikedr View PostI'm not 100% sure, but the Easy Trigger plug-in may permit you to do this without scripting.
Comment
Comment