Calculate Time Based on Temperature

Hey,

What I’m after is to calculate the time our hot tub will arrive at 100 degrees
based on it’s current temperature. It heats at a rate of 10 degrees an hour.

So basically, I think, I just need to subtract the hot tub temperature from 100, then multiply by 6 and add that as minutes to the current time and set the HotTubReadyTime variable to that.

The script adjusts variables in my home automation app, Indigo, which knows of the variables.
For example ws_Temp_HotTub holds the hot tub temperature, ClockTimeAmPm holds the current time in a standard format. ( 8:46 pm), and HotTubReadyTime holds the time the same way.

tell application “IndigoServer”

set theTemp to (value of variable “wsTemp_HotTub” as integer)
set theTime to (100 - theTemp)
set theTime to (theTime * 6)
set the value of variable “HotTubReadyTime” to time string of ((date (value of variable “ClockTimeAmPm”)) + (theTime * minutes))

end tell

The above script returns the error “Can’t get date”.

Any help greatly appreciated!

Thanks,

Carl

Hi Carl.

Try keeping the date stuff outside application ‘tell’ statements.

tell application "IndigoServer"
	set theTemp to (value of variable "wsTemp_HotTub" as integer)
	set timeNow to (value of variable "ClockTimeAmPm")
end tell

set theTime to ((100 - theTemp) / 10) * hours
set readyTime to time string of ((date timeNow) + theTime)

tell application "IndigoServer" to set the value of variable "HotTubReadyTime" to readyTime

Also, since you’ve now made 89 posts to MacScripter, try using its [applescript][/applescript] tags when posting code. :slight_smile: There’s a button which inserts them around selected text in the posting window on the posting page or you can write them in yourself.

Perfect, sorry about not using the script block.

Thanks,

Carl

Hi Karl,

Nigel was saying to keep it out of the tell block, so that the key words don’t clash. Is that a word? :slight_smile: Clash looks different when you write it.

Editted: come to think of it, it’s easier to read the script also, especially when you don’t know the target apps dictionary.

gl,

Thanks for all the help. I will be posting any future scripts within the script “quotes” so it shows correctly.

Carl

Thanks kel1. I should have explained that. Written date specifiers (‘date’ + text or text variable) often don’t work in application ‘tell’ statements because they conflict with a similar keyword or token belonging to the applications themselves.