Ok. I made multiple errors and the try/catch was swallowing them. I still don't know if I found and fixed them all, but I think I did.
Mistake #1 I need to add datetime import into the engine python code Mistake #2 Double quotes inside an eval statement cause syntax errors because they are themselves inside double quotes. Use single quotes instead. This was a problem when testing, it might not be a problem when reading from a file. Mistake #3 It's not &H, dummy! it's %H I still don't know if it's actually working. We'll see soon. On Wednesday, March 27, 2019 at 9:25:19 PM UTC-7, gjr80 wrote: > > Hmm, that is getting complex. Just be careful, you have introduced a > dependency on python module datetime and looking at the WeeWX module > weewx.engine (that contains the StdCalibrate code) it does not import > datetime. The line that performs the evaluation for StdCalibrate is > wrapped in a try..except but I believe it will raise and error so you > will know if datetime is an issue. I could be wrong and it is possible the > import error could come up and be swallowed and you would not be aware. > Best bet would be to pay particular attention to the corner cases to make > sure your expression performs as expected. > > Gary > > On Thursday, 28 March 2019 12:04:43 UTC+10, [email protected] wrote: >> >> Well, It seems to work, meaning that I don't get any syntax errors. I'll >> have to wait until tomorrow afternoon if it's sunny to see for sure. I >> tried to put in a time specific fix - >> >> outTemp = extraTemp1 if outTemp>(extraTemp1 + 4) and >> datetime.utcfromtimestamp(dateTime).strftime("&H")>16 and >> datetime.utcfromtimestamp(dateTime).strftime("&H")<20 else outTemp >> >> There's a pretty good chance I've screwed up the logic but at least the >> syntax works in stdCalibrate >> >> Thanks for your help/ >> >> On Wednesday, March 27, 2019 at 6:25:33 PM UTC-7, gjr80 wrote: >>> >>> Meant to link the relevant section >>> <http://weewx.com/docs/usersguide.htm#StdCalibrate> from the Users Guide >>> <http://weewx.com/docs/usersguide.htm> but forgot. It does not say it >>> in so many words but you can anything that can 'evaluated' in a single >>> line. Most folks tend to think of simple formulae involving one or more >>> variables but the single line version of the python if..then..else >>> statement lets you bring in conditional evaluation as well. >>> >>> If you are interested in the python behind [StdCalibrate] then anything >>> that you can do in the python eval() >>> <https://docs.python.org/2/library/functions.html#eval> function can be >>> used. The available variables are observation field names in the loop >>> packet or archive record being processed, eg: outTemp, outHumidity, rain >>> etc >>> >>> Gary >>> >>> On Thursday, 28 March 2019 11:15:28 UTC+10, [email protected] wrote: >>>> >>>> That's exactly what I was looking for. >>>> >>>> I want to set outTemp, but otherwise exactly what I need. I didn't know >>>> that I could put an if statement there. Can I use other python code there >>>> to be able to look up the time? Is this in the documentation someplace? >>>> >>>> I'll try it out now. >>>> >>>> On Wednesday, March 27, 2019 at 6:03:35 PM UTC-7, gjr80 wrote: >>>>> >>>>> Hi, >>>>> >>>>> You could put an entry in [StdCalibrate] in weewx.conf to set outTemp >>>>> or extraTemp1 to whatever you want. Something like: >>>>> >>>>> [StdCalibrate] >>>>> [[Corrections]] >>>>> extraTemp1 = extraTemp1 if outTemp > extraTemp1 + 6 else >>>>> outTemp >>>>> >>>>> or you could flip the equation around and change outTemp. Another >>>>> approach would be to put your composite temperature in another field such >>>>> as extraTemp2: >>>>> >>>>> [StdCalibrate] >>>>> [[Corrections]] >>>>> extraTemp2 = extraTemp1 if outTemp > extraTemp1 + 6 else >>>>> outTemp >>>>> >>>>> The 2nd approach will preserve you outTemp or extraTemp1 data and >>>>> should see extraTemp2 saved to the database. >>>>> >>>>> Note that the above is untested and the '6' assumes you are using US >>>>> customary units in your database - if not then 6 needs to be converted to >>>>> C. >>>>> >>>>> Also, depending on your requirements you could achieve a similar >>>>> result with some in line python code in your template. This would work >>>>> fine >>>>> for displaying current data but will not give you the aggregates that you >>>>> get from having the composite data in the database. You could easily work >>>>> in your time based requirements as well (pseudo code - if 17 < hour < 19 >>>>> display extraTemp1 else display outTemp). You could even use a >>>>> combination >>>>> of [StdCalibrate] and some python inline code to get the best of both >>>>> worlds. >>>>> >>>>> Gary >>>>> >>>>> On Thursday, 28 March 2019 10:28:29 UTC+10, [email protected] wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> I have been using Weewx v3.5.0 for a few years now. I have an >>>>>> Accurite weather station with the thermometer, rain gauge and anemometer >>>>>> in >>>>>> a single unit. In order to get the rain gauge and anemometer to give >>>>>> useful >>>>>> readings, I mounted it on the roof where it's away from all the trees. >>>>>> It's >>>>>> the best location for wind and rain, but it sucks for the temperature >>>>>> much >>>>>> of the time. I have a white roof and the temp up there is often 10degF >>>>>> warmer than ambient. >>>>>> >>>>>> To get around that, I built my own wifi thermometer and put it in a >>>>>> much better location. Details of the build here >>>>>> <https://hackaday.io/project/101680-solar-powered-wifi-temperature-sensor-for-weewx> >>>>>> . >>>>>> >>>>>> The new thermometer gives more accurate readings almost all the time. >>>>>> However, a few minutes in the late afternoon, I get direct sunshine on >>>>>> it >>>>>> and the temp spikes. It can spike by 20 degrees sometimes and is >>>>>> screwing >>>>>> with my long term high temp data. It's worst this time of year, before >>>>>> the >>>>>> oak trees leaf out and block the afternoon sun. >>>>>> >>>>>> I'm recording the Accurite data in extraTemp1 and my thermometer in >>>>>> outTemp. I want to write some code to put the extraTemp1 value in >>>>>> outTemp >>>>>> if outTemp is more than 6 degF higher than extraTemp1. Ideally I'd only >>>>>> do >>>>>> this between 5-7pm local time, but doing it all the time would be ok. >>>>>> The >>>>>> problem I'm having is finding a good place to do the comparison. The >>>>>> service that reads outTemp doesn't have the extraTemp1 value. The code >>>>>> that >>>>>> reads the Accurite data and stuffs it into extraTemp1 doesn't have the >>>>>> outTemp data. Does anyone have a suggestion on where to do this >>>>>> comparison? >>>>>> >>>>>> I've tried fixing it up after the fact with a SQL query. It works, >>>>>> but I'd like to do it in real time rather than go back and fix the data >>>>>> later. >>>>>> >>>>> -- You received this message because you are subscribed to the Google Groups "weewx-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
