[SOLVED] Sonoff dual - Roller shutter

Thanks a lot. It´s exactly that i´m looking for. I´m very happy!!!

Now i´m trying to make it work but…

2018-07-29 18:36:18.210 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Sonnoff6 2': Could not cast NULL to java.lang.Number; line 38, column 66, length 23

According to what I saw. The item is not initialized. How do I have to do?

Thank you so much,


Ah, yes, forgot to mention this… I have persisted the item (plus restoreOnStartup) and in an old version of the rule there was a part which took care of that…

Please add a line like this:

if (!(Sonoff6.state instanceof Number)) Sonoff6.postUpdate(0)

right after the logDebug() in the first rule.

I have added the line in my posting above…


Thanks a lot, i maked it work with that line, but i couldn’t use the open all, close all function. When i check the log, it’s says:

`2018-08-02 00:34:07.082 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type REGEX

2018-08-02 00:34:07.085 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'mqttSonoff6_2'

2018-08-02 00:34:07.081 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Sonoff6': The name 'Sonoff6Dur' cannot be resolved to an item or type; line 17, column 9, length 10

2018-08-02 00:34:07.143 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type REGEX

2018-08-02 00:34:07.147 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'mqttSonoff6_2'`

Thanks again!


Sorry, forgot to kill this line:


this part is not necessary to make the rules work, it was only to give additional information when creating the rules.

In question of the REGEX warning, I don’t use REGEX at all in this rules, so this issue can’t be mine :wink:

Same for the given new state is NULL, couldn't post update for 'mqttSonoff6_2', as I only used mqttSonoff6_2.sendCommand(ON|OFF), there is nothing which could send a NULL to mqttSonoff6_2 in my rules.

1 Like

Thanks a lot! You did it! One more question. How do you reset the rule so i can tell that the roller shutter is full open?



I don’t do this :slight_smile: I simply send the shutter to up (or down) position. (e.g. morning and evening)
The Sonoff will switch off after maximum runtime, and after that the upper or lower position should be reached. As the maximum runtime is used, the counter should go to 100% or 0%.

Thanks a lot for all your help! Now i´ll check the tasmota mod.


Yes, this is on my roadmap, too :slight_smile:

why go out of synck? and the cause?

…I take advantage of the post to thank Hudo Hartmann for his excellent work

I used your code with a shelly 2.5 and the tasmota firmware. Everything works perfectly, moreover the buttons connected to the shelly also allows me to have feedback in case of using the buttons near the window. The only problem is that if you press up and down together from OH the motor is powered in both directions, risking damage. How can I fix this? I’m not very good with the rules

Please set option 14 to 1 (this is relay interlock). When using the current version of Tasmota, the command is “Interlock 1”

thanks for the reply, I solved. Specific only, to help those who read the post, with the latest version of Tasmota ( the Option14 command has been replaced by “interlock” 0 (off) or 1 (on)

There is a technique to overcome this situation. (I used to see it used in connection with stepper-motor controlled valves, with no sensing.)
It relies on your mechanism being capable of being safely driven to a mechanical end stop, plus a bit more.
If it is going to bend or break something in that situation, Sod’s Law says that will happen anyway one day - so I’d imagine rollers would be safe for this “abuse”?!

Anyway, the point is;
Say you know your roller takes at most 15 secs for full travel.
If you drive it this way or that for 17 secs, you know (barring faults) that it must have got to the fully open/closed stop, regardless of where it started.
In my stepper-motor example, at system start it would always (over) drive the valve fully closed and zero the software step position counter.

In openHAB, you’d want to intercept any fully-open or fully-closed commands so that you could apply that overdrive, and then reset your calculated position.

You could invent a special calibration routine of course, but I’d imagine among your ordinary controlling rules there will be requirements for fully open/closed that can exploited for this purpose. Periodic self-calibration.

You don’t even need the “full 17 seconds” or whatever if you are reasonably confident the calibration doesn’t get too far adrift - just add a second or two to calculated travel time from “here” to “end”.

I studied the rule, with my basic notions, to be able to integrate google home. If I understand, by logDebug the rule assigns the percentage to the item Sonoff6 and calculates the activation time. While the second rule acts on the three cases UP DOWN and STOP.
I also can’t understand the meaning of 6-2 in

logDebug ("sonoff", "6-2: received command: {}", receivedCommand)

To integrate GH I had thought of creating two more items (without sitemaps) one for OPEN and one for CLOSE, this to tag them with [“Switchable”] and insert a third rule that set the item Sonoff6 equal to zero (opening) or to 100 (closure)

I made some attempts but with negative results, is it possible to get help?
thank you

logDebug() will only output something if you set the log level to DEBUG, this is done via karaf console by using the command

log:set DEBUG org.eclipse.smarthome.model.script.sonoff

As I created two rules to control the sonoff, I wanted to get some difference between the output, but I wanted the same logger to be used (named “sonoff”)

I added this to the end of the rule to command opening and closing from GH. It is also necessary to create an item with the “Switchable” tag for GH. It seems to work well, the only flaw that I can’t correct is a small input to the motor at the end of the stroke. Example: 100% shutter (closed) I send the closing command and should do nothing, instead it activates the motor for a moment.

rule "google home up"
   Item rolleshutter received command ON
     if (Sonoff6.state !== 0 )  {	
	rule "google home down"
   Item rollershutter received command OFF
     if (Sonoff6.state !== 100 ) {

Rules can be picky about comparing percentage types; try

if ( (Sonoff6.state as Number) !== 0 )  {

thanks for your help. I found the error:

if (Sonoff6.state ! = 0 )

instead of:

if (Sonoff6.state !== 0 )
1 Like

Please don’t mix up things:

= -> set var to, e.g. i = 4
== -> compare the value, is it the same? e.g. if(i == 4)
=== -> compare if identical, e.g. if(i === null)
!= -> not the same value
!== not identical

So, if comparing a value to null, you should use === or !==, if comparing to a value (like 0), you have to use == or !=.

1 Like

ok, thanks, I mark the reminder of the examples