oh sorry youâre right⊠I use TimeOfDay that way already⊠but also show them in sitemap. so I need them anyway
my old db was older than 5 years and I changed a lot of Item names and changed their persistence quite often it wasnât inconsistent but with many unused fields full of old crap⊠So it was the easiest way to get rid of that old stuffâŠ
I need help with the new OpenHAB3 JavaScript time of Day rule. So far Iâve done the Time of Day rule with the java script. It setup the 3 instances to run the script. I did not know how to set a schedule tag. I also setup the TimeOfDay String and the TimesOfDay Group. Do I have to copy all the DateTime items into the items folder like I would in OpenHAB2. Any help would be appreciated. Thanks!!!
You need one DateTime item for each transition that you want, not all of them.
Those have to be member of the group and have the ephemeris metatags set.
To initialize them for the first time Iâd recommend using âopenhab:sendâ from the console. Just the time is sufficient.
Not sure what you mean by â3 instances/schedule tagâ, though.
In addition to Michaelâs excellent advice, did you also install the time_utils and time_mgr libraries? Those are required as well.
Setting it up should be something like the following:
copy the timeUtils.js and timerMgr.js files from my repo and place them in $OH_CONF/automation/lib/javascript/community.
copy the YAML from the repo and paste it into a new rule in MainUI
create the TimesOfDay Group and TimeOfDay String Item
Create a set of DateTime Items for a given type of day. You need a set for default at a minimum but can add a set for weekend and holiday as well. These Items need to have metadata set (see the readme for the rule or the original post for details) to identify the Item as a Time of Day Item and which type of day itâs for and other config info as necessary.
Populate these Items with a value. There are lots of ways to do this including from a binding like Astro, from the console as Michael indicates. You can create an input card, update it from a rule, etc. I particularly like opening the -Scratchpad- from the developer sidebar (alt-shift-d in main UI) and can write some quick commands to execute in there.
I used the openhabian install of OpenHAB3. I canât find the $OH_CONF/automation/lib/javascript/community directory to put the .js files
I did put the YAML in a new rule. It created the following:
When:
When a member of TimesOfDay changed
When the system has reached start level 20
One minute after midnight
Then:
execute a given script
I did create the TimesOfDay and TimeOfDay string items
The $OH_CONF/automation/lib/javascript/community directory does not exist by default, but itâs where the script looks for its helper scripts. For a standard install, $OH_CONF is â/etc/openhabâ. Not sure if thatâs the same with openhabian. Just create it and put the scripts there.
Hi,
got the TOD rule Working and everything ist fine until i restart OH. All TOD Items that are astro related are OK but the static times that are set via UI or CLI command are not populatet by the persistence.
I am using rrd4j DB as a persitance service wit the following setup. Could somebody be so good to check if there is an error that is screwing up the restorOnRestart of my TOD items.
Hmm, that âTimesOfDay*â line should be sufficient, as that persists all members of the group.
I use MapDB as the startup persistance service, so I really donât know if thatâs a rrd4j problem or not.
But your config file looks good to me.
Ok, I think Iâm all set except for the meta tags on my time of day items. I do have emphersis setup with my location. Iâve looked around the forums for awhile and canât figure it out.
DateTime types are not yet supported by rrd4j. There was an issue filed to add it and if I remember correctly it was even worked on. For all I know itâs working in the snapshots. But for the release you need to use MapDB for DateTime Items.
What part canât you figure out? The namespace, value, and configuration required are described in the original post with examples from .items files.
I think I have the custom metadata setup now. All my times of day are showing the correct time. However I am seeing the error message below when the YAML script runs.
2021-01-13 09:08:18.732 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID âe6414ca5c6â failed: :5:59 Missing close quote
Return the value or a key value from the Itemâs metadata
^ in at line number 5 at column number 59
Here is the first part of that script:
// Imports var logger = Java.type(âorg.slf4j.LoggerFactoryâ).getLogger(âorg.openhab.model.script.Rules.TimeOfDayâ); scriptExtension.importPreset(âdefaultâ); this.Ephemeris = (this.Ephemeris === undefined) ? Java.type(âorg.openhab.core.model.script.actions.Ephemerisâ) : this.Ephemeris; this.ZonedDateTime = (this.ZonedDateTime === undefined) ? Java.type(âjava.time.ZonedDateTimeâ) : this.ZonedDateTime; // Get Metadata query stuff this.FrameworkUtil = (this.FrameworkUtil === undefined) ? Java.type(âorg.osgi.framework.FrameworkUtilâ) : this.FrameworkUtil; this._bundle = (this._bundle === undefined) ? FrameworkUtil.getBundle(scriptExtension.class) : this._bundle; this.bundle_context = (this.bundle_context === undefined) ? this._bundle.getBundleContext() : this.bundle_context; this.MetadataRegistry_Ref = (this.MetadataRegistry_Ref === undefined) ? bundle_context.getServiceReference(âorg.openhab.core.items.MetadataRegistryâ) : this.MetadataRegistry_Ref; this.MetadataRegistry = (this.MetadataRegistry === undefined) ? bundle_context.getService(MetadataRegistry_Ref) : this.MetadataRegistry; this.Metadata = (this.Metadata === undefined) ? Java.type(âorg.openhab.core.items.Metadataâ) : this.Metadata; this.MetadataKey = (this.MetadataKey === undefined) ? Java.type(âorg.openhab.core.items.MetadataKeyâ) : this.MetadataKey; // Constants var ETOD_ITEM = âTimeOfDayâ; var ETOD_GROUP = âTimesOfDayâ; var DAY_TYPES = [âdefaultâ, âweekdayâ, âweekendâ, âdaysetâ, âholidayâ, âcustomâ]; var EXPECTED = "Invalid metadata for Item! "
+ "Expected metadata in the form of etod=âSTATEâ[type=âdaytypeâ, set=âdaysetâ, file=âuriâ] "
+ âwhere set is required if type is dayset and file is required if type is custom.â;
var ETOD_NAMESPACE = âetodâ; // Load TimerMgr this.OPENHAB_CONF = (this.OPENHAB_CONF === undefined) ? java.lang.System.getenv(âOPENHAB_CONFâ) : this.OPENHAB_CONF; load(OPENHAB_CONF+â/automation/lib/javascript/community/timerMgr.jsâ); load(OPENHAB_CONF+â/automation/lib/javascript/community/timeUtils.jsâ); /**
Return the value or a key value from the Itemâs metadata
@param {string} item name of the item
@param {string} namespace metadata namespace to pull
@param {string} key index into the configuration dict for the value
@return {string} value assocaited with key or null if it doesnât exist.
*/
Also, where do I link my individual lights to the correct time of day with the correct dimness.
Thanks for the help.
Please use code fences when posting code. I canât begin to tell what might be going on here with it all munged together on one line like that.
But as Michael suggests, copy a known working version again and see if that works. The error is complaining about syntax so a bad edit or copy and paste is the likely culpret.
I have the following set up which is probably a little more involved than most would want to use when just getting started.
I have a series of Groups for each time of day with names following this patter:
TOD_Lights_ON_<TOD>, for example TOD_Lights_ON_DAY
TOD_Lights_OFF_<TOD>, for example TOD_Lights_OFF_DAY
I add as members all those lights I want to have turn on at the start of the DAY time period to the first group and all those I want to turn off at the start of the DAY time period to the second.
Sorry about the code fences. I copied the link that Michael mentioned with the raw view of the code. Still getting an error on the code. Here is what the OpenHAB3 log shows:
2021-01-13 10:54:50.452 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'e6414ca5c6' failed: <eval>:2:6 Expected ; but found :
- id: "1"
in <eval> at line number 2 at column number 6