But how can i send a command (as i insert in the console of a sonoff) ?
But do a dimmer returns a value?
Example
Item dimmer is e number?
That depends very much on your specific setup. You NEED to read and understand the docs, both for openhab in general, and the specifics of the binding and devices you use, and search the forum. I can’t do that for you.
Sorry for being harsh, but I can’t even begin to explain things if you don’t have an understanding of the basic OH concepts, and I won’t use my time to explain those, since they are already in the docs.
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’
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.
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’
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.
No it doesn’t work.
But is it possible to do the debug?
In the Timer function la x is in sec?
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.
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?
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
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
You have unerstood.
But i doesn’t work
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
That’s because the item name is Apertura, not apertura as I noticed in the screenshots you showed.
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
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.
No, you did not
How can i resolve it?