Virtual device for usage last day/week/month

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Sooty
Member
Member
Posts: 204
Joined: Sat Mar 22, 2008 11:29 pm
Location: United Kingdom

Re: Virtual device for usage last day/week/month

Post by Sooty »

Even if you don't use this, perhaps it will help to give you an insight into scripting with Homeseer.

I have attached a zip file containing a vb script and an ini file.
Please Note: This is not fully tested but it is based on a script used in my system.

I have purposely left out error checking (apart from 1 try catch as an example) to make the code clearer and I have only added the day and week devices so perhaps you could add the month and year devices yourself.

The ini file needs to go into your /homeseer/config folder and the script into your /homeseer/scripts folder.

You will need to edit the first few lines of the script as I have assumed that the main meter device is Q3 and that Today, Yesterday, This Week and Last Week will be devices A1, A2, A3 and A4.

You can run the "UpdateValues" function from a Homeseer event at any time and all relevant devices will be updated.

If you run the "ResetCounters" function from a Homeseer event between 00:00:00 and 00:01:00 the devices will be updated, so yesterday's device becomes today's value and today's device value becomes 0. If it is Monday then the last week's value becomes this weeks etc...

Paul..
Attachments
PowerMeter.zip
(1.2 KiB) Downloaded 351 times
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Virtual device for usage last day/week/month

Post by raymonvdm »

I made another script to control a Z-Wave device by script but the actual device is not responding

Code: Select all

Sub Main(parm as object)
hs.SetDeviceStatus("Q74",3)
hs.SetDeviceLastChange("Q74",now)
End Sub
The device is changing in HomeSeer but the actuale dimmer is not doing anything. Strange isn`t it?
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
Sooty
Member
Member
Posts: 204
Joined: Sat Mar 22, 2008 11:29 pm
Location: United Kingdom

Re: Virtual device for usage last day/week/month

Post by Sooty »

The preferred method for controlling a Z-Wave device from a script would be hs.transmit.

Sub Main(parm as object)
hs.Transmit("Q74", "Dim", 50, 0, False, False )
End Sub

In your example you have changed the status of the device within Homeseer but not actually transmitted anything over the Z-Wave network.

Paul..
raymonvdm
Senior Member
Senior Member
Posts: 1153
Joined: Sun Dec 18, 2011 1:23 am

Re: Virtual device for usage last day/week/month

Post by raymonvdm »

This is working indeed, i also needed to add al sleep timer to make it a blinking light

Code: Select all

Sub Main(parm as object)
hs.Transmit("Q74", "Dim", 50, 0, False, False )
System.Threading.Thread.Sleep(1000)
hs.Transmit("Q74", "Dim", 70, 0, False, False )
System.Threading.Thread.Sleep(1000)
hs.Transmit("Q74", "Dim", 50, 0, False, False )
System.Threading.Thread.Sleep(1000)
hs.Transmit("Q74", "Dim", 70, 0, False, False )
System.Threading.Thread.Sleep(1000)
hs.Transmit("Q74", "Dim", 50, 0, False, False )
System.Threading.Thread.Sleep(1000)
hs.Transmit("Q74", "Dim", 70, 0, False, False )
End Sub
Running HS3PRO on PC with Z-Wave / OpenTherm / Plugwise / RFXcom / MQTT / XAP400 / Logitech Media Server and Squeezelite on PI`s
AshaiRey
Senior Member
Senior Member
Posts: 1310
Joined: Mon Feb 02, 2009 5:27 pm
Location: Netherlands
Contact:

Re: Virtual device for usage last day/week/month

Post by AshaiRey »

Instead using System.Threading.Thread.Sleep consider using hs.WaitSecs if you run into problems because this will suspend/block the thread.

{source] http://www.homeseer.com/support/homesee ... meseer.htm
hs.WaitSecs
Purpose
This function waits a number of seconds. This will also allow other operations to take place in HomeSeer by giving up the CPU. It will also keep a script from timing out. The function will not return until the number of seconds have elapsed.

Parameters
Parameter: seconds
Type: integer
Description: This is the number of seconds to wait.

Returns
None.

Example
sub main()

hs.speak "hold on while I wait for 3 seconds"
hs.WaitSecs 3
hs.speak "ok, I'm done"

end sub
Bram
Post Reply

Return to “Homeseer Scripts Forum”