weird script behavior
James Sentman
james at sentman.com
Wed Feb 5 10:23:08 EST 2020
That is a very good catch Philippe!
the status verb will return a boolean, and you’re comparing it to a number which does make sense for the error message you’re getting. I only see that in the one place in the script down towards the bottom, but I would definitely review the logic throughout as I’m not entirely sure of my proofreading skills yet ;)
I would also verify that the name of your “Winter” unit really does start with a space? I see it in the script as “ Winter” each time. Which is fine, I sometimes do the same just to force things to sort the way I want them to, but since thats also interesting I wanted to mentino it.
The only other things I would suggest are just style questions. Everytime you use an XTension verb there is some overhead as it calls back into the program and looks up the information and returns it. It’s not a lot, but it adds up. Not that it’s a problem as the script probably runs in plenty of time, but you could speed it up some, and reduce changes for typos down in the code by pulling some of the most called for values into local variables to compare rather than asking XTension for the same thing over and over again. There aren’t many but you could pull Thermostat (State) and Winter into locals for faster comparison something like:
set isWinter to (status of “ Winter”)
set thermostatState to (status of “Thermostat (State)”)
and then do the comparisons just like:
if isWinter then
if thermostatState then
if (value of "Ceiling fan - Happyroom") is less than 100 then
brighten "Ceiling fan - Happyroom" to 100
end if
if (value of "Ceiling fan - LR") is less than 100 then
brighten "Ceiling fan - LR" to 100
end if
if (value of "Ceiling fan - TV") is less than 100 then
brighten "Ceiling fan - TV" to 100
end if
end if
else
if not thermostatState then
if (status of "Ceiling fan - Happyroom") is true then
turnoff "Ceiling fan - Happyroom"
end if
if (status of "Ceiling fan - LR") is true then
turnoff "Ceiling fan - LR"
end if
if (value of "Temp - TV room") is greater than 70 then
if (value of "Ceiling fan - TV") is not equal to 66 then
brighten "Ceiling fan - TV" to 66
else
if (value of "Ceiling fan - TV") is not equal to 33 then
brighten "Ceiling fan - TV" to 33
end if
end if
end if
end if
end if
and so forth as you access those values quite a bit throughout the script.
For myself I’ve also created an attachment handler called:
on turnonConditional( theUnit)
if not (status of theUnit) then
turnOn theUnit
end if
end turnonConditional
on turnoffConditional( theUnit)
if (status of theUnit) then
turnOff theUnit
end if
end turnoffConditional
on dimConditional( theUnit, theValue)
if (value of theUnit) is not equal to theValue then
dim theUnit to theValue
end if
end dimConditional
This doesn’t remove any extra calls, but makes the code easier to read and few places to mistype a unit name as you could just do things like:
if isWinter and not thermostatState then
turnoffConditional( "Ceiling fan - Happyroom”)
dimConditional( “Ceiling fan - TV”, 33)
turnoffConditional( “Ceiling fan - LR)
end if
rather than the last 3 comparisons for ceiling fans in the script. Again those last things won’t affect the actual reliability or speed of the script, but is just a style suggestion.
Thanks,
James
> On Feb 5, 2020, at 4:50 AM, Philippe SCHMUCK <philippe-schmuck at orange.fr> wrote:
>
> There is one line that seems to be wrong :
>
> if (status of "Ceiling fan - TV") is not 33 then
>
> Shoud be
>
> if (value of "Ceiling fan - TV") is not 33 then
>
>
>
> Philippe
>
>
> > Message du 05/02/20 01:38
> > De : "Chuck" <xtension4osx at mac.com <mailto:xtension4osx at mac.com>>
> > A : "XTension" <xtensionlist at machomeautomation.com <mailto:xtensionlist at machomeautomation.com>>
> > Copie à :
> > Objet : *** SPAM *** weird script behavior
> >
> >I have a script that runs when the furnace turns on. It opens vents as needed and turns on ceiling fans. Sometimes it works just fine and other times it give me this error.
>
> Feb 4, 2020 4:26:57 PM Executing global script: HVAC script
> Feb 4, 2020 4:26:57 PM HVAC script has run
> Feb 4, 2020 4:26:57 PM Script Error from "HVAC script" message: -1700: Can’t make true into type number, date or text.
>
Thanks,
James
James Sentman http://www.PlanetaryGear.org http://MacHomeAutomation.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.machomeautomation.com/pipermail/xtensionlist/attachments/20200205/493a46e1/attachment.html>
More information about the XTensionList
mailing list