Getting Daily High Temperature from Weathersnoop

This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
Forum rules
This is a legacy forum which is locked for new topics. New topics should be started in one of the other forums under Extending Indigo
bluenoise
Posts: 143
Joined: Sat Aug 23, 2008 3:21 pm

Getting Daily High Temperature from Weathersnoop

Post by bluenoise »

I tried to find this answered already to no avail.

I would like to know the daily high temperature at my house as it will be used to determine how often I water the lawn and garden. I cannot find an easy way to get this value short of creating a scheduled event that polls the temperature every ~30 minutes or so to set the high temperature. I don't see this state available from the Weathersnoop plugin, nor do I see it in Weathersnoop's "Weather Properties," but WS does track this information within the application as a marker on the graphical thermometer. Would it need to be among WS's Weather Properties to be available to the plugin's states?

Thanks!
User avatar
berkinet
Posts: 3441
Joined: Tue Nov 18, 2008 2:08 pm
Location: Berkeley, CA, USA & Mougins, France

Re: Getting Daily High Temperature from Weathersnoop

Post by berkinet »

I wrote a high/low AppleScript function for the wunderground script that does what I think you are looking for. You can probably adapt this to run in a trigger that fires each time the temp changes.

First, you need to create these Indigo variables...
  • Last_High_Time
    Last_High_Temp
    Last_Low_Time
    Last_Low_Temp
    Local_High_Time
    Local_High_Temp
    Local_Low_Time
    Local_Low_Temp
Then, the function is...

Code: Select all

on SetHighLow(currentTemp, thedate)
	iset thedate to thedate as text
	set theTime to word 6 of thedate & ":" & word 7 of thedate & " " & word 8 of thedate
	
	tell application "IndigoServer"
		-- First, check if we have a new high		
		set oldHigh to the value of variable "Local_High_Temp" as real
		if oldHigh is equal to "" then set oldHigh to 0 as real
		if currentTemp is greater than oldHigh then
			set the value of variable "Local_High_Temp" to temp_f
			set the value of variable "Local_High_Time" to theTime
		end if
		
		-- And now, check if we have a new high	
		set oldLow to the value of variable "Local_Low_Temp" as real
		if oldLow is equal to "" or oldLow is equal to 0 then set oldLow to 100 as real
		if currentTemp is less than oldLow then
			set the value of variable "Local_Low_Temp" to temp_f
			set the value of variable "Local_Low_Time" to theTime
		end if
	end tell
end SetHighLow
Finally, I call the function like this...

Code: Select all

set observation_time to do shell script "date"
set currentTemp to temp_f as number
SetHighLow(currentTemp, observation_time)
Oh, and don't forget to have a scheduled action to reset the high/low variables just after midnight each night. An embedded AppleScript something like the following should do the trick...

Code: Select all

set the value of variable "Last_High_Temp" to the value of variable "Local_High_Temp"
set the value of variable "Last_High_Time" to the value of variable "Local_High_Time"
set the value of variable "Last_Low_Temp" to the value of variable "Local_Low_Temp"
set the value of variable "Last_Low_Time" to the value of variable "Local_Low_Time"
set the value of variable "Local_High_Temp" to 0
set the value of variable "Local_Low_Temp" to 100
set the value of variable "Local_High_Time" to "12:01 AM"
set the value of variable "Local_Low_Time" to "12:01 AM"
When this is all working, Last_High_Temp, Last_High_Time, Last_Low_Temp & Last_Low_Time will record the previous day's high/low temp data. The "local_" variables are tracking the current day's data.
bluenoise
Posts: 143
Joined: Sat Aug 23, 2008 3:21 pm

Re: Getting Daily High Temperature from Weathersnoop

Post by bluenoise »

Thank you, berkinet, for the great reply. I forgot I had those HiLo variables in my variables list and had to do a little digging to see what was setting them as they hadn't been updated in quite a while. It turns out I lacked the scheduled event to reset those variables at the start of each new day, so they were holding old HiLo values.

To make use of them, I wrote this script to be run each night at 11:50:

Code: Select all

from datetime import date

# Indigo Variables
runDripToday = indigo.variables[542358241]	# Set to true if the drip should run today
dripDayInterval = indigo.variables[1228875068]	# Nominal watering period in days
todaysHighTemp = indigo.variables[53056838]	# The high temperature of the day in degreesF
dripTemperature = indigo.variables[1965665196]	# Above this temperature, the drip should run

# Reset runDripToday variable
indigo.variable.updateValue(runDripToday, "false")

# Grab today's date and convert it to a day count
today = date.today()
dayNumber = date.toordinal(today)

# Ensure dripDayInterval is an integer
interval = int(dripDayInterval.value, base=10)

# Set runDripToday to true if the daily high temperature exceeded the threshold set
# by dripTemperature, or if the number of days set by dripDayInterval has passed.
if ((dayNumber % interval == 0) or (todaysHighTemp.value >= dripTemperature.value)):
	indigo.variable.updateValue(runDripToday, "true")
	indigo.server.log("runDripToday Enabled")
else:
	indigo.server.log("runDripToday Disabled")
I set up the variables in Indigo so that I can easily change the temperature threshold and the nominal watering interval, even from Indigo Touch. The scheduled event that runs the drip irrigation is called daily, but only runs if two variables are true, runDripToday (set by this script) and enableSprinklers, which is a global variable I use in all my sprinkler schedules so I can toggle them with a single variable. I run the drip every three days (dripDayInterval = 3) in the early morning, but will run it if the previous day exceeded the dripTemperature, regardless how many days have passed since the last watering.
Locked

Return to “Extending Indigo with Plugins and Python”