(30.06.2022, 13:24)asgeirsb Wrote: Hi! Great script, thanks!
I'm having an issue, trying to export the 250 byte strings for sunrise and sundown and calculated sunrise and sundown, but it won't let me export those objects.
Also I did some adjustment to the script and byte the same times as 3 byte date / time but I still can't export to BACnet. Any reason it won't let me?
Do you need this values in a SE (EBO) system? If yes, i have ported this function to Plain English so you have all values as BACnet datetime objects there..
(30.06.2022, 13:24)asgeirsb Wrote: Hi! Great script, thanks!
I'm having an issue, trying to export the 250 byte strings for sunrise and sundown and calculated sunrise and sundown, but it won't let me export those objects.
Also I did some adjustment to the script and byte the same times as 3 byte date / time but I still can't export to BACnet. Any reason it won't let me?
Do you need this values in a SE (EBO) system? If yes, i have ported this function to Plain English so you have all values as BACnet datetime objects there..
-- ***** Astronomic clock module Version 1.0 Created by Erwin van der Zwart ***** ---- ********* Use this script as resident script and run every 60 seconds ******** ---- ****** This script makes use of rscalc function inside common functions ****** ---- ******************************** SET PARAMETERS ****************************** ---- Set output addressadressoutput = '1/1/1'-- 1 bit output for control object-- Set time shifting addressesaddressshifttimesunrice = '1/1/2'-- 1 or 2 byte signed integer to be able to adjust/offset calculated sunrise time (set min/max on object)addressshifttimesundown = '1/1/3'-- 1 or 2 byte signed integer to be able to adjust/offset calculated down time (set min/max on object)-- Set feedback adressesaddresssunrise = '1/1/4'-- 255 byte object for user feedback, shows calculated sunrise timeaddresssundown = '1/1/5'-- 255 byte object for user feedback, shows calculated sundown timeaddresssunriseshifted = '1/1/6'-- 255 byte object for user feedback, shows with offset calculated sunrise timeaddressundownshifted = '1/1/7'-- 255 byte object for user feedback, shows with offset calculatedsundown time-- Set location coordinateslatitude = 52.52198--Zwolle Netherlands, Look at 'http://www.mapcoordinates.net/en' for other locationslongitude = 6.08213--Zwolle Netherlands, Look at 'http://www.mapcoordinates.net/en' for other locations-- ******************************** END PARAMETERS ****************************** ---- ********************* DON'T CHANGE ANYTHING UNDER THIS LINE ****************** ---- Function to calculate switching times based and output valuefunctionastronomic(latitude,longitude,shiftedsunrise,shiftedsundown)
localnow = os.date('*t')
localsunrise, sunset = rscalc(latitude, longitude, now) --Zwolle Netherlands, See http://www.mapcoordinates.net/en for other locationssunriseorg = string.format('%d:%.2d', math.floor(sunrise / 60), sunrise % 60)
sunsetorg = string.format('%d:%.2d', math.floor(sunset / 60), sunset % 60)
sunrisenew = sunrise + shiftedsunrisesunsetnew = sunset + shiftedsundownsunrisetime = string.format('%d:%.2d', math.floor(sunrisenew / 60), sunrisenew % 60)
sunsettime = string.format('%d:%.2d', math.floor(sunsetnew / 60), sunsetnew % 60)
localminutes = now.hour * 60 + now.minnowdark = minutes < sunriseneworsunsetnew < minuteslocalt = {sunricenormal = sunriseorg, sundownnormal = sunsetorg, sunriceshifted = sunrisetime, sundownshifted = sunsettime, output = nowdark}
return (t)
end-- Get values for timeshiftingshiftedsunrise = grp.getvalue(addressshifttimesunrice) or0-- Make minutes negative to switch earlyer than normal calculated sunrice and positive to switch later than normal calculated sunriceshiftedsundown = grp.getvalue(addressshifttimesundown) or0-- Make minutes negative to switch earlyer than normal calculated sundown and positive to switch later than normal calculated sundown-- Call function to calculate astroinfoastroinfo = astronomic(latitude,longitude,shiftedsunrise,shiftedsundown)
-- Set new sunrice time (unshifted)currentvalue = grp.getvalue(addresssunrise)
ifastroinfo.sunricenormal ~= currentvaluethengrp.update(addresssunrise, astroinfo.sunricenormal)
end-- Set new sundown time (unshifted)currentvalue = grp.getvalue(addresssundown)
ifastroinfo.sundownnormal ~= currentvaluethengrp.update(addresssundown, astroinfo.sundownnormal)
end-- Set new sunrice time (shifted)currentvalue = grp.getvalue(addresssunriseshifted)
ifastroinfo.sunriceshifted ~= currentvaluethengrp.update(addresssunriseshifted, astroinfo.sunriceshifted)
end-- Set new sundown time (shifted)currentvalue = grp.getvalue(addressundownshifted)
ifastroinfo.sundownshifted ~= currentvaluethengrp.update(addressundownshifted, astroinfo.sundownshifted)
end-- Set output value to output objectcurrentvalue = grp.getvalue(adressoutput)
ifastroinfo.output == truethenifcurrentvalue == falsethengrp.write(adressoutput, true)
endelseifcurrentvalue == truethengrp.write(adressoutput, false)
endend
If you want to combine it with a scheduler then make a 'and' logic, put the output of this script to input 1, output of the schedular to input 2 and the control object to the output of your 'and' logic.
BR,
Erwin
Hi Erwin,
very easy question.
adressoutput = '7/0/4' -- 1 bit output for control object