Position estimator for shutters

You can trigger a rule when an Item state changes to NULL

I usually write rules to deal with NULL states e.g. if you don’t (yet) know what XX is then you might not want to doing YY after all.

Is this only possible for items, or also for map variables? If so, how?

When
   ShutterStartTimestamps changes to NULL
Then
...

?

There is no way to trigger a rule from any kind of contents change of any variable, no.

Who cares if a variable is null, until you go to use it. Then you can test if it is null and decide what to do about that.
This is looping back around to -

and requiring you to have extra rules to detect “known” positions i.e. you can infer it must have got to one end or other.

It’s true that I do not care if it is null as long as I do not use it, but mistrust every variable blows up the code and if it is “a constant” it is annoying if I have to check it for every first use in the rule and think about an exit strategy.
The idea of the rule “initialize ShutterStartTimestamps” is to set default values, so they are not null anymore. If they are still null, I do not need a initialisation.

Therefore, I thought as a remedy I could at least check if one “constant” is null, and in that case reinitialise them. In the UI it is also possible to call a other rule, so I thought it is also possible via scripting

Maybe look more closely at what you do.

Pre-loading your timestamps Map with dummy “9999” values is avoidable, unnecessary.
At the time of use, you could instead test if an entry exists, and if not then act as though you found “9999” (or do whatever was really wanted to deal with first use).

The durations Map is indeed a more difficult proposal. Clearly you want some value at first use.
As I said previously, my gut feel for these would be to hold them in
Items as they are a kind of partner-property to each of your individual shutter Items. The usual Items persist/restore mechanisms could then be left to manage populating them.
But you certainly don’t have to do it that way.

You can call a “script” from a UI or file based rule. They’re not used very often, because you cannot pass stuff in or out. So far as I know, in neither case can the script share ‘globals’ (like a Map) with a calling script. As long as you want to do something like interact only with some Items, they are usable. Updating a bunch of Items with preconfigured constants, for example.

In your example, they’re all alike - but I guess you are planning ahead for them being individually tailored up/down each Item.
I think I’d cheat, once again testing to see if a value is present, and if not then assuming some default (25.0?) temporarily.

What problem are you trying to fix here, it goes wrong when you edit the rules file? How often is that going to happen in normal use? (This goes to choosing an easy bodge or a difficult technically-correct solution.)

Yes, all data is always lost if I save the rule file and during testing it is saved frequently. But, you are wright, once it is fine it will not be resaved frequently (unless there is the next rule I’d like to add). For now, I think, best approach is to define them during initialisation as well like it is done at e.g. Cannot assign a value in null context. and HashMap - what is wrong?

You can have many rules files. If you keep your shutters riles in one file and other stuff in a different file(s), then you you wouldn’t mess up shutters by editing other stuff.

Hi Anno_Nym! I am looking into the same challange as you, maybe you can help me a bit.

I have OH3, RPI4 and communicates via MQTT to a RFlink bridge.

My question: How can I get my Sunblinds down or up for example 20% of the total length or via a position which I fill in via a – for example -slider cell?

I would like to bring my Sunblinds down based on how much sun I would like to have in my living room. In the current set-up I have to watch how far the sunblind goes and if I would like to stop: I hit the stop button. Preferably I am able to use the slider cell, but don’t know how to link /configire this to the sunblinds commands UP/STOP/DOWN.

I tested with a script with a javascript SLEEP command (for example for 5 a 6 seconds), that works, but is not connected to a slider or Rollershutter cell. I am fully aware that my sunblind motor doesn’t give the state back, so own calculation of the position in % is precise enough.

Later on I would like to connect a wind meter and light meter, based on the moment of the day the sunblinds should go down for 20,30or 70% of the total lengts. First tings first, If iam able to put the % via a cell, that would be fine!

I saw you have made a script, since i am a new bee: How did you configure your systeem? Now I have a MQTT thing, linked into a Rollershutter item and published this item on the page in OpenhabPanel. What do I have to configure to get your script working? I have only one Sunblind… Really appriciate your help!

Just a word of caution;this is a technically ambitious project. You will learn a lot if you stick with it :smiley:

But you might first choose to get familiar with rules and timing with something a bit simpler, like an automated light. Find out how to use a rules based timer, instead of a simple delay, you’ll need that for blinds control.

1 Like

Hi @konehead ,
In my case my shutters are controlled via tasmota. In that way I used the “backlog” functionality to close the relay, wait some time and open the relay again. The time I have to delay I calculated in advance according to the actual position to the target position.
→ the observer and the controller are decoupled. So like @rossko57 wrote above you must ensure to set autoupdate=false

1 Like

I had a similar problem where Somfy roller shutters remotes have been replaced by openhab. I used a RFXCom to send the actual commands to the shutters and the position was estimated using some JSR233 automation rules, allowing absolute positon control.

Only one additional item is needed for each shutter, everything is managed by a JS class instantiated for each shutter…

You can find the JS code and the associated items definition in the following VASRollershutter.js gist. This is performed on an openhab 2.5 instance but I guess only minor adaptations should be needed for OH3.

1 Like

@ Rossko57 Both thanks for steering me into this direction.

Wow, this looks like a full sollution for my position issue! Will try to implement it next week into my configuration. My end goal is/was to connect it with Homekit. So use the WindowCovering option, and allign the WindowCovering postion in Homekit with the actual postion of the roller shutters. I’ll keep you posted!

Merci!

I updated the gist to work with OH3.

To use it, one must first follow precisely the instructions inIvan’s Helper Libraries - OH3, Python, JavaScript to install the JS helper libraries, particularly to use the files according the the right pull request (by downloading this link for example https://github.com/CrazyIvan359/openhab-helper-libraries/archive/5a452ef2367176654fa408c18917947c1502697b.zip )

The VASRollerShutter.js file should be installed in automation/jsr223/javascript/personal and the js-timeout-polyfill.js in automation/lib/javascript/personal.

Then in openhab.log you should see (a restart might be needed):

2021-04-30 07:48:55.457 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/javascript/personal/VASRollerShutter.js'                                                                                            │
2021-04-30 07:48:55.589 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'js' with identifier: file:/etc/openhab/automation/jsr223/javascript/personal/VASRollerShutter.js                                                  │
2021-04-30 07:48:55.997 [INFO ] [javascript.NOCONFIG.vasrollershutter] - VASRollershutter (re)loaded!                                                                                                                                                       │
2021-04-30 07:48:56.426 [DEBUG] [sr223.javascript.NOCONFIG.core.rules] - Added rule [VASRollerShutter] 

In order to test you can add the items as defined, without the rfxcom channel, and create roller shutter cells in webui for the ...VAL items. If you use the commands, you should see in the `events.log` the positions updated and the actual commands sent back to the ...CMD items.

@tarag
Today, finaly I found time to install your solution. Unfortantly I do get an error from VAL which I don’t understand. Please can you help me?

I get back:
2021-05-07 20:23:50.517 [ERROR] [javascript.NOCONFIG.VASRollerShutter] - Error during the evaluation of ‘rule: VASRollerShutter’ at line 212 at column -1 in JavaScript traceback (most recent call first):TypeError: Cannot read property “processCommand” from undefinedat VASRollershutterExecute (:212)2021-05-07 20:23:50.519 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule ‘8d78c9a2-e34e-40fb-91f4-2a33fda718a2’: Fail to execute action: 12021-05-07 20:23:50.520 [DEBUG] [e.automation.internal.RuleEngineImpl] - java.lang.RuntimeException: Fail to execute action: 1
What I did:
A) I changed your script (VASRollershutter.js), deleted 3 of the 4 shutters. Since I have one shutter
Added the timing: new VASRollershutter(“F0_Zonnescherm_achtertuin_RS_VAL”, 56000, 53500);
B) Didn’t change: js-timeout-polyfill.js
C) I uploaded the scripts to the locations according your instruction
D) I created an virtual item: Rollershutter F0_Zonnescherm_achtertuin_RS_VAL “Zonnescherm achtertuin” [ “WindowCovering” ] { autoupdate=“false” }
E) Updated the physical item =>: Rollershutter F0_Zonnescherm_achtertuin_RS_CMD “Zonnescherm achtertuin”
F) Restarted the Openhab service

Logfile after service stop/start:

Logfile after running UP or Down from: F0_Zonnescherm_achtertuin_RS_VAL

You should correct the line

new VASRollershutter(“F0_Zonnescherm_achtertuin_RS_VAL”, 56000, 53500);

To:

new VASRollershutter(“F0_Zonnescherm_achtertuin”, 56000, 53500);

Only the prefix of the items’ name should be used in this line.

Whoppaa! Works! Really thanks for your help and solution! Happy as a child in a candy shop!

@tarag
Hi one other question (maybe off topic for your script_: Do you use homekit to control your rollershutter? In homekit I do see the rollershutter (as WindowCovering). But the values are opposite. In OH the status is: 0 (= closed), in homekit it is fully Open. 98% open in Homekit is 2 in OH.

Glad that you made it work.

I am not using this anymore so I don’t know if it is inverted or not in HomeKit, but a quick search on the forum should give your the answer as I see some posts on this issue.

Yes will do! Have added a slider to my OH panel, so funny: if I put the slide from 0 > 50, after this commando the dot of the slider moves automatically in line with the position of the roller shutter. It Is next level!

je vous remercie beaucoup!