[SOLVED]How does a dimmer work?

(Francesco) #8

look that

rule "apertura1"

when 

item LivingRoom_Light1 changed to ON

then 

x = (apertura.state * 24)
 thread::sleep(x)
LivingRoom_Light1.sendCommand(OFF)
end

24 because the time to closed my shutter is 24 sec.
I want to use the dimmer to detrmine the % of closure
But it doesn’t work

But the “X” of the command “sleep” is in seconds?

when i save the rules i have:

2019-03-19 15:14:38.820 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘apertura.rules’

2019-03-19 15:14:38.827 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘apertura.rules’ is either empty or cannot be parsed correctly!

2019-03-19 15:14:39.946 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘apertura.rules’ has errors, therefore ignoring it: [5,1]: no viable alternative at input ‘item’

0 Likes

(Anders Alfredsson) #9

This looks better, I can see you are trying now. The error is because item needs no be capitalized: Item.
Then there’s some other small errors:

rule "apertura1"

when 

Item LivingRoom_Light1 changed to ON

then 

var x = (apertura.state * 24)
 Thread::sleep(x)
LivingRoom_Light1.sendCommand(OFF)
end

However, using Thread::sleep for long periods of time (>1 second) is a bad idea because it can block other rules from running, see here for more info. Instead use a timer

rule "apertura1"

when 

Item LivingRoom_Light1 changed to ON

then 

var x = (apertura.state * 24)
 createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end

It has the same result, but is safer to use.

I can’t guarantee everything is correct, typing on my phone and cannot test the rules.

0 Likes

(Francesco) #10

I tried but when i save the file. rules on the log i have this:

2019-03-19 18:44:27.846 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘apertura.rules’

2019-03-19 18:44:27.859 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘apertura.rules’ is either empty or cannot be parsed correctly!

2019-03-19 18:44:29.209 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘apertura.rules’

0 Likes

(lipp_markus) #11

This is expected behavior if you are using samba to access the rule files. Java is trying to load the file before it is fully written, hence the warning…and the last log message that is logged when the complete file finally is read, tells you that all went well eventually.

0 Likes

(Francesco) #12

No it doesn’t work.
But is it possible to do the debug?

In the Timer function la x is in sec?

0 Likes

(lipp_markus) #13

Unfortunately, this statement gives no information as to what exactly does not work…hence makes it not possible to help you.
maye a few more pointers for your to read: How to ask a good question / Help Us Help You

Yes you can add logInfo statements; the docs are your friend: https://www.openhab.org/docs/configuration/actions.html#logging-actions
Using logInfo statements can be used to log the values of all variables and Item.state and also, if well done, tell you exactly at which line your rule is failing. Use them generously.

Sorry, I don;t understand even the question…what is “la x”…but here a guess: the argument x for the timer is represented in seconds.

0 Likes

(Francesco) #14

Look that

2019-03-19 20:13:01.873 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘apertura’: Unknown variable or command ‘*’; line 9, column 10, length 19

it seems that the symbol “*” (moltiplication) is not recognized

what is the right symbol for moltiplication?

0 Likes

(Francesco) #15

i report all part:



rule "apertura"

when 

Item LivingRoom_Light1 changed to ON

then 

var x = (Apertura.state * 24)
	
 createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end

0 Likes

(Ron) #16

I see a few issues with your rule.

First, a dimmer item has a value between 0 and 100 (where 0 also means OFF and 100 also stands for ON for most devices). You should divide the value by 100 to get a time between 0-24 seconds.
However, I’m not sure this works like you expect. Let’s say you move the Apertura slider to 50% and hit the switch, the value 50 wll be used in the rule and the shutter will move to halfway, in 12 seconds. Then you move the slider to 70% and the value 70 will be used in the rule, activating the switch for ~17 seconds.

This is probably because the DSL rules engine doesn’t know how to convert the types and assumes they ar strings (which cannot be multiplied). Try this:

var x = (apertura.state as Number) * 0.24
0 Likes

(Francesco) #17

You have unerstood.
But i doesn’t work :disappointed_relieved::disappointed_relieved::disappointed_relieved:

rule "apertura"

when 

Item LivingRoom_Light1 changed to ON

then 

var x = (apertura.state as Number * 0.24)
	
 createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end

The rule seems good.
I do not uderstand where is the problem
now i have this error
2019-03-19 20:59:28.134 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘apertura’: The name ‘apertura’ cannot be resolved to an item or type; line 9, column 10, length 8

0 Likes

(Ron) #18

That’s because the item name is Apertura, not apertura as I noticed in the screenshots you showed.

0 Likes

(Francesco) #19

i changed it


0 Likes

(Francesco) #20

When i set a value (ex 37) of the dimmer i have:

2019-03-19 22:33:14.495 [ome.event.ItemCommandEvent] - Item ‘DimmerCam’ received command 37

2019-03-19 22:33:14.508 [nt.ItemStatePredictedEvent] - DimmerCam predicted to become 37

2019-03-19 22:33:14.531 [vent.ItemStateChangedEvent] - DimmerCam changed from UNDEF to 37

2019-03-19 22:33:14.543 [vent.ItemStateChangedEvent] - DimmerCam changed from 37 to UNDEF

I don’t uderstand why DimmerCam go to 37 and then go automatically to UNDEF

Infact now if i push on OPEN i have

2019-03-19 22:33:38.896 [ome.event.ItemCommandEvent] - Item ‘LivingRoom_Light1’ received command ON

2019-03-19 22:33:38.913 [vent.ItemStateChangedEvent] - LivingRoom_Light1 changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2019-03-19 22:33:39.105 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘apertura’: Could not cast UNDEF to java.lang.Number; line 11, column 11, length 25


rule "apertura"


when 

Item LivingRoom_Light1 changed to ON

then

 var x = (DimmerCam.state as Number * 0.24)
	
 createTimer(now.plusSeconds(x)) [|
LivingRoom_Light1.sendCommand(OFF)
]
end

0 Likes

(Rossko57) #21

This is autoupdate feature at work.
Autoupdate listens for commands sent to Items, and predicts what the effect will be on the Item state.
Why? For a quick response - some devices may give a prompt status update back to openHAB, some may be slow, some may never give one, some Items are not bound to any real device.

So -
2019-03-19 22:33:14.495 [ome.event.ItemCommandEvent] - Item ‘DimmerCam’ received command 37
Here’s your command.

2019-03-19 22:33:14.508 [nt.ItemStatePredictedEvent] - DimmerCam predicted to become 37
Here’s autoupdate’s prediction, or guess, at the outcome.

2019-03-19 22:33:14.531 [vent.ItemStateChangedEvent] - DimmerCam changed from UNDEF to 37
Here’s your Item actually getting updated by autoupdate

2019-03-19 22:33:14.543 [vent.ItemStateChangedEvent] - DimmerCam changed from 37 to UNDEF
What’s this then? This has come from the device binding, the real state of the device.
But the binding to your Item is in error so you get the UNDEF.

You can disable autoupdate for your Item, which will stop the guesswork part.

But of course the real problem is that your MQTT setup is not updating your Item properly.

0 Likes

(Udo Hartmann) #22

No, you did not :slight_smile: detail

0 Likes

(Francesco) #23

How can i resolve it?

0 Likes

(Anders Alfredsson) #24

The problem could be anywhere in the communication between your sonoff and openhab.

  1. What info does your sonoff publish and to which mqtt topics?
  2. In what format does it publish the info?
  3. Is your topic channel on openhab configured correctly to receive the info?
  4. Do you need to transform the info to make openhab understand it?
0 Likes

(Francesco) #25

Maybe the problem is on the channel.
I set the Dimmer “DimmerCam” but the field of the state and command in openhab are blank.
This because i want to use the dimner only to determine the time that the rule wait for turn off the switch.
I’m not expect e response from the sonoff
I think this is correct.
Don’t you think that?

If i erase the variable x and i put a number as argument of the command TIMER it works correctly

0 Likes

(Rossko57) #26

So, this is just a value to be used for timing?
Why have you made it a Dimmer Item, a Number would be more sensible surely.
If you only want to use the value in a rule why have linked it to MQTT?

0 Likes

(Francesco) #27

That’s right. So i should unlink from the Mqtt broker.
This evening i will try and i hope to resolve.
I continue to use the dimmer only to set a % of opening of the blind

0 Likes