script help - formula syntax

Posted on
Sun Sep 04, 2022 11:53 am
dtich offline
Posts: 798
Joined: Sep 24, 2005

script help - formula syntax

hey all,

having predictable trouble with this formula -- currently compiler doesn't like the exp notation (well, it compiles, but runtime no like). i can't sort out how to do it properly in py. any thoughts, mainly on the final line?

adding this handler because in this heat, for some reason, often getting -data unavailable- back from the noaa plugin query, the db on the noaa side is not doing the calculations to F for some reason, or populating the text strings. but the C values seem to be updated regularly, so i'm trying to fallback on that in these cases:

Code: Select all
##use other vars if '- data unavailable -'
if cnttemp == "- data unavailable -":
   cnttemp = (wthrStation.states['temperatureC']-32)*5/9
if cnthumid ==  "- data unavailable -":
   cnthumid = 100 * {exp[17.625 * wthrStation.states['dewPointC']/(243.04 + wthrStation.states['dewPointC'])]/exp[17.625 * wthrStation.states['temperatureC']/(243.04 + wthrStation.states['temperatureC'])]}


thanks for any thoughts!
Attachments
Screenshot 2022-09-04 at 10.49.29 AM.jpg
Screenshot 2022-09-04 at 10.49.29 AM.jpg (444.71 KiB) Viewed 587 times
Screenshot 2022-09-04 at 10.43.34 AM.png
Screenshot 2022-09-04 at 10.43.34 AM.png (224.62 KiB) Viewed 587 times

Posted on
Sun Sep 04, 2022 3:24 pm
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: script help - formula syntax

Please post the entire script so we can verify which is line 11.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Sep 04, 2022 3:29 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script help - formula syntax

that line 11 error is from another script i think.

this script is fine but for that formula i believe. i'm just adding that bit.

thx for looking.



Code: Select all
##var ref
#indigo.devices[204052749] # "weather station_van nuys"
#indigo.devices[228772392] # "weather station_burbank"
#indigo.devices[1643443948] # "weather station_lax"
#indigo.variables[41620001] # "Weather_Condition"
#indigo.variables[162814321] # "WeatherCurrentHumidity"
#indigo.variables[1354783145] # "WeatherCurrentTemp"
#indigo.variables[1787162613] # "WeatherCurrentWindSpeed"

##init stations
kbur = indigo.devices[228772392]
kvny = indigo.devices[204052749]
klax = indigo.devices[1643443948]


##determine which station to use-- if bur over two hours old, fallback to vny, if older than two hours, fall back to lax
from datetime import datetime
timeDeltaBur = datetime.now() - kbur.lastChanged
timeDeltaVny = datetime.now() - kvny.lastChanged
timeDeltaLax = datetime.now() - klax.lastChanged


if timeDeltaBur.seconds > 7200 or timeDeltaBur.days > 0: #if bur out of date
   if timeDeltaVny.seconds > 7200 or timeDeltaVny.days > 0: #if vny out of date

      wthrStation = indigo.devices[1643443948] # assign "weather station_lax"
      indigo.variable.updateValue(752974756, "KLAX") # "WeatherCurrentStation"
      indigo.server.log("KBUR Time Since Update: "+ str(timeDeltaBur), type="Irrigation")
      indigo.server.log("KVNY Time Since Update: "+ str(timeDeltaVny), type="Irrigation")

   else:
      wthrStation = indigo.devices[204052749] # assign "weather station_van nuys"
      indigo.variable.updateValue(752974756, "KVNY") # "WeatherCurrentStation"
      indigo.server.log("KBUR Time Since Update: "+ str(timeDeltaBur), type="Irrigation")

      #log bur last obs
      kburobs = kbur.states['observationDate']
      #indigo.server.log("KBUR Last Obs: "+ str(kburobs), type="Irrigation")

else:
   wthrStation = indigo.devices[228772392] # assign "weather station_burbank"
   indigo.variable.updateValue(752974756, "KBUR") # "WeatherCurrentStation"


##log current station
indigo.server.log("Current Station: "+ str(wthrStation.address), type="Irrigation")


##set temp vars from station info     
cnttemp = wthrStation.states['temperatureF']
cnthumid = wthrStation.states['humidity']
cntwind = wthrStation.states['windMPH']
cntcond = wthrStation.states['currentCondition']
cntobsdate = wthrStation.states['observationDate']

##use other vars if '- data unavailable -'
#if cnttemp == "- data unavailable -":
#   cnttemp = (wthrStation.states['temperatureC']-32)*5/9
#if cnthumid ==  "- data unavailable -":
#   cnthumid = 100 * {exp[(17.625 * wthrStation.states['dewPointC'])/(243.04 + wthrStation.states['dewPointC'])]/exp[17.625 * wthrStation.states['temperatureC']/(243.04 + wthrStation.states['temperatureC'])]}


##update ind vars
indigo.variable.updateValue(1354783145, str(cnttemp))
indigo.variable.updateValue(162814321, str(cnthumid))
indigo.variable.updateValue(1787162613, str(cntwind))
indigo.variable.updateValue(41620001, str(cntcond))
indigo.variable.updateValue(700138389, str(cntobsdate))


##email if lax out of date 1day+
email_address = "dtich@pacbell.net"
email_body = "Station KLAX updated " + str(timeDeltaLax) + " ago." + "\r\n" + "Current Station: " + str(wthrStation.address)

if timeDeltaLax.days > 0:
#if timeDeltaLax.days > 0 and wthrStation.address == "KLAX":

   indigo.server.sendEmailTo(email_address, subject="ALERT Fallback Weather Station Out of Date", body=email_body)

Posted on
Sun Sep 04, 2022 3:33 pm
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: script help - formula syntax

Your syntax for exp() is wrong, I'd fix that first.

https://www.w3schools.com/python/ref_math_exp.asp

After that, if the Python interpreter detects an error, it'll spit out a line number. Need that. Note that the code you posted has those lines commented out?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Sep 04, 2022 3:43 pm
dtich offline
Posts: 798
Joined: Sep 24, 2005

Re: script help - formula syntax

"math." is what i needed. i looked it up too, but only found the ** method, which did not work.

so, thanks much for that. works.

thx @flyingdiver appreciate the link

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests