eTrack

Plug-ins, scripts, and other software to improve your home automation experience.
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

eTrack

Post by kw123 »

The discussion seems to be closed, but here one more question:

I have several pairs of dimmers combined (responder and controller).
Deleted all variables for each of the second dimmers.
Still using the triggers for the 2. dimmer, but calling the applescript function with the main dimmer name. That should avoid double or wrong counting. Is that correct?

Also I have 2 thermostats ( out of 4 ) that run against one AC/Heater for one room each - one upstairs and one downstairs. Both can start the AC and are opening and closing valves for the individual rooms. Any suggestion how to handle that, should be he same as for the dimmers?

thx,
great app

Karl
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: eTrack applescript error if no iMeter variable defined

Post by kw123 »

Added the following to the code in the "on trackEnergyReset()" (indicated with -- added)

If there is no eTrackiMeter_ .. defined in Indigo, apple script stops with error message that variable iMeterVars is not defined. Added test to verify that variable exists.


Thx

Karl

Code: Select all

on trackEnergyReset()
	(* ================================================
		This primary handler resets all eTrackCost*, eTrackTotalCost, eTrackKWH*,
		eTrackTotalKWH, and eTrackGrandTotal* Indigo variables to zero. This will also
		send the raw INSTEON command to all tracked iMeter Solos devices to reset it's
		internal accumulated energy total to zero.
		
		Expects: nothing
		
		Returns: true
	=================================================== *)
	
	tell application "IndigoServer"
		
		-- Reset tracked iMeter Solo devices
		set iMeterVars to every variable whose name begins with "eTrackiMeter_"
		
		
		--------
		--		                            check if any variable is set
		set iMexists to "true" --        added
		try -- added
			iMeterVars --      check if this works, then there is something in the variable, Indigo makes this variable undefined if there is no hit.
		on error -- added
			set iMexists to "false" --   added
		end try --                              added
		
		if iMexists = "true" then --     yes variables are set, continue  -- added
			repeat with thisVar in iMeterVars
				set thisiMeter to value of thisVar
				set theAddress to address of device thisiMeter
				send insteon raw cmd1 128 cmd2 0 to address theAddress
			end repeat
		end if ---                                 added
		set thisVar to null


nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

Re: eTrack

Post by nsheldon »

kw123 wrote:Still using the triggers for the 2. dimmer, but calling the applescript function with the main dimmer name. That should avoid double or wrong counting. Is that correct?
I'm assuming that those paired dimmers are set up in a 2-way switch configuration where only one dimmer actually provides power to the light while the other dimmer just controls the load-bearing dimmer. Correct? Assuming that's the case, as long as Indigo keeps the "on" condition of the load-bearing dimmer in sync with the non-load bearing dimmer, there's no need to execute the AppleScript function when the non-load-bearing dimmer state changes because the eTrack triggers fire when the state changes, not when INSTEON commands are received.
kw123 wrote:Also I have 2 thermostats ( out of 4 ) that run against one AC/Heater for one room each - one upstairs and one downstairs. Both can start the AC and are opening and closing valves for the individual rooms. Any suggestion how to handle that, should be he same as for the dimmers?
This may require a bit of eTrack trigger tweaking. The best way to handle this would probably be to do what you've suggested. Pick one thermostat as a primary one to track with eTrack, then modify the trigger for the second thermostat so that it executes the AppleScript function for the first. Additionally, so that eTrack doesn't double-count energy when both thermostats are on, you'll need to add a condition to the eTrack AC, Fan, Furnace, and Heat On triggers for each thermostat so that if one thermostat is already on, the other thermostat trigger doesn't execute. The same is true for the AC, Fan, Furnace, and Heat Off triggers.
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

Re: eTrack applescript error if no iMeter variable defined

Post by nsheldon »

kw123 wrote:Added the following to the code in the "on trackEnergyReset()" (indicated with -- added)

If there is no eTrackiMeter_ .. defined in Indigo, apple script stops with error message that variable iMeterVars is not defined. Added test to verify that variable exists.


Thx

Karl

Code: Select all

on trackEnergyReset()
	(* ================================================
		This primary handler resets all eTrackCost*, eTrackTotalCost, eTrackKWH*,
		eTrackTotalKWH, and eTrackGrandTotal* Indigo variables to zero. This will also
		send the raw INSTEON command to all tracked iMeter Solos devices to reset it's
		internal accumulated energy total to zero.
		
		Expects: nothing
		
		Returns: true
	=================================================== *)
	
	tell application "IndigoServer"
		
		-- Reset tracked iMeter Solo devices
		set iMeterVars to every variable whose name begins with "eTrackiMeter_"
		
		
		--------
		--		                            check if any variable is set
		set iMexists to "true" --        added
		try -- added
			iMeterVars --      check if this works, then there is something in the variable, Indigo makes this variable undefined if there is no hit.
		on error -- added
			set iMexists to "false" --   added
		end try --                              added
		
		if iMexists = "true" then --     yes variables are set, continue  -- added
			repeat with thisVar in iMeterVars
				set thisiMeter to value of thisVar
				set theAddress to address of device thisiMeter
				send insteon raw cmd1 128 cmd2 0 to address theAddress
			end repeat
		end if ---                                 added
		set thisVar to null


Thanks for the contribution. Good catch!
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: eTrack

Post by kw123 »

Have added the attached code to the end of the eTrack script file.
It reads out the parameters and writes them to a coma delimited file for use in excel

A scheduled action calls this function and then the reset function 1 minute before midnight.
Result is a file that has all usage data for each day concatenated - one line per device/type (several for a thermostat - fan, heater, ac ..)
It is a completely de-normalized format, can be used in excel pivot tables.
File size is ~2K for 40 devices per day.
The file eTrackout.txt gets put into the $HOME/Documents/ directory

I have not done the iMeter section yet.

Seems to work fine.

Use as you you see fit.

Karl


+++ updated the file exist section, did not work properly.

Code: Select all

on writefileeTrack()
	(* ================================================
		This primary handler write out all data to file in coma delimted format
		
		Expects: nothing
		
		Returns: true
	=================================================== *)
	
	set rightNow to (current date)
	set rightNow to ((month of rightNow) as integer) & "/" & ((day of rightNow) as integer) & "/" & ((year of rightNow) as integer) & " " & time string of rightNow
	set rightNow to rightNow as text
	
	set outputfile to "\"$HOME/Documents/etrackout.txt\" "
	
	--create headerline if called first time	
	set myPath to (path to home folder) as text
	set myPath to myPath & "Documents:etrackout.txt"
	--create headderline if called first time	
	tell application "Finder"
		if exists myPath then
			set create to "no"
		else
			set create to "yes"
		end if
	end tell
	
	
	if create = "yes" then
		set outcmd to "echo  \"" & "Dev, Date-Time, "
		set outcmd to outcmd & "GrandTotalCOST, GrandTotalKWH, GrandTotalTherms, CostPerKWH, CostPerTherm"
		set outcmd to outcmd & " ," & "Cost, TotalCost ,TotalTime ,TotalCycles, KWH, TotalKWH, Therms, TotalTherms, ThermsPerHour"
		set outcmd to outcmd & " \"  >> " & outputfile
		do shell script outcmd
	end if
	
	(*	to be done, dont have the hardware , need to check code which variables get set
	-- Reset tracked iMeter Solo devices
	set iMeterVars to every variable whose name begins with "eTrackiMeter_"
	--------
	--		                            check if any variable is set
	set iMexists to "true" --        added
	try -- added
		iMeterVars --      check if this works, then there is something in the variable, Indigo make this variable undefined if there is no hit.
	on error -- added
		set iMexists to "false" --   added
	end try --                              added
	
	if iMexists = "true" then --     yes variables are set, continue  -- added
		repeat with thisVar in iMeterVars
			set thisiMeter to value of thisVar
			set outcmd to "echo " & "\" " & " VAR  " & thisiMeter & "\"  >> " & outputfile
			do shell script outcmd
		end repeat
	end if ---                                 added
*)
	
	
	set outcmd0 to rightNow
	
	tell application "IndigoServer"
		set dat to (get value of variable "eTrackGrandTotalCost") as text
		set outcmd0 to outcmd0 & ", " & dat
		
		set dat to (get value of variable "eTrackGrandTotalKWH") as text
		set outcmd0 to outcmd0 & " ," & dat
		
		set dat to (get value of variable "eTrackGrandTotalTherms") as text
		set outcmd0 to outcmd0 & " ," & dat
		
		set dat to (get value of variable "eTrackCostPerKWH") as text
		set outcmd0 to outcmd0 & " ," & dat
		
		set dat to (get value of variable "eTrackCostPerTherm") as text
		set outcmd0 to outcmd0 & " ," & dat
		
	end tell
	
	
	tell application "IndigoServer"
		-- eTrackCost variables
		set costVars to every variable whose name begins with "eTrackCost_"
		set ni to number of items in costVars
	end tell
	
	set nn to 1
	repeat while nn < ni
		tell application "IndigoServer"
			set w to item nn of costVars
			set nam to name of w
			set tid to AppleScript's text item delimiters
			set AppleScript's text item delimiters to "_"
			set devName to (text item 2 of nam) as text
			set AppleScript's text item delimiters to tid
			
			
			set outcmd to "echo " & "\"" & devName & ", " & outcmd0
			
			set dat to "-0"
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTotalCost_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTotalTime_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTotalCycles_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackKWH_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTotalKWH_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTherms_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackTotalTherms_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			set dat to "-0"
			set nam to "eTrackThermsPerHour_" & devName
			if variable nam exists then set dat to (get value of variable nam) as text
			set outcmd to outcmd & " ," & dat
			
			
		end tell
		
		set outcmd to outcmd & "\"  >> " & outputfile
		do shell script outcmd
		set nn to nn + 1
	end repeat
	
	

Last edited by kw123 on Mon Jul 01, 2013 7:55 pm, edited 1 time in total.
User avatar
kw123
Posts: 8705
Joined: Sun May 12, 2013 4:44 pm
Location: Dallas, TX
Contact:

Re: eTrack

Post by kw123 »

there is one mistake in the fix

The "end if" has to go after the set thisVar to null, the "set" should not be executed if the variable does not exis. Does not seem to create a problem though if executed.

Code: Select all

			set thisVar to null
		end if 

Karl
nsheldon
Posts: 2469
Joined: Mon Aug 09, 2010 2:12 pm
Location: CA
Contact:

Re: eTrack

Post by nsheldon »

Another great addition Karl. Thanks!
Post Reply

Return to “Nathan Sheldon Software”