I am trying to learn / create a couple of simple dimmer rules / commands, but through various attempts, nothing happens.
I am using Philips Hue, and have all the binding etc, and they are controlled without any problems manually via openhab.
Firstly, I have been trying to create a Rule for a light which is over our Bird cages, and for it to go off at 6.00pm say, or a given time.
I used Cronmaker to create the time code, and followed various guides to try and get this to work, none of which did.
The most recent I tried was this:
rule "Turn Off Birds Light"
when
item Dimmer Light_IN_Frontroom_Birds received command or
Time cron "0 0 18 1/1 * ? *"
then
var Number percent = 0
if(Dimmer Light_IN_Frontroom_Birds.state instanceof DecimalType) percent = Dimmer Light_IN_Frontroom_Birds.state as DecimalType
postUpdate(Dimmer Light_IN_Frontroom_Birds, percent); 100
end
I have also tried even a simple direct command (found on the CinemaVision Forum for Kodi), which was the following:
1st you have to use sendCommand instead of postUpdate as postUpdate only updates the state of an item, but does not send this state through the binding.
2nd you donât have to use the word Dimmer in rules to specify an item, this is .items only.
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
rule "Turn Off Birds Light"
when
Time cron "0 0 18 * * ?" // 18:00:00, every day, every month, every weekday, don't care about year
then
Light_IN_Frontroom_Birds.sendCommand(0)
end
If you want to do a (more or less) smooth fadeout instead of instant blackout, try this:
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.joda.time.DateTime
var int percent = 0
var Timer fade_Timer = null
rule "Turn Off Birds Light"
when
Time cron "0 0 18 * * ?" // 18:00:00, every day, every month, every weekday, don't care about year
then
if (Light_IN_Frontroom_Birds.state instanceof DecimalType) {
percent = ((Light_IN_Frontroom_Birds.state as DecimalType)/5).intValue * 5 //round to 5
fade_Timer = createTimer(now.plusMillis(500)) [|
Light_IN_Frontroom_Birds.sendCommand(percent)
if (percent > 0) {
percent = percent - 5
fade_Timer.reschedule(now.plusMillis(500))
}
]
}
end
Hey Udo,
Can you help me for the below topic?
I want to setup a Dimmer item, with which I waant to bind the http binding, I can use the rule present in the demo.rules file, but not sure how to send the percentage value of it to my http server running on Raspberry pi3. Any Ideas will be appriciated.
Well, given a dimmer item bound to http, this should be very easyâŠ
Dimmer myDimmer "My http Dimmer is [%d %%]" {http=">[*:POST:http://www.domain.org/home/lights/23871/?status=%2$s&type=text] <[http://www.domain.org/weather/openhabcity/daily:60000:REGEX(.*?<title>(.*?)</title>.*)]"}
(Item definition from documentation)
Now to change the value, either use a slider in Basic UI or something similar, with ârealâ sliders, or use INCREASE/DECREASE commands and a rule to set the value:
rule "My http dimmer"
when
Item myDimmer received command
then
if (receivedCommand == DECREASE) {
myDimmer.sendCommand((myDimmer.state as DecimalType) - 5)
}
else if (receivedCommand == INCREASE) {
myDimmer.sendCommand((myDimmer.state as DecimalType) + 5)
}
end
I have no idea, why you get a loop. you can try to use
when
Item myDimmer received command DECREASE or
Item myDimmer received command INCREASE
then
as the trigger part, but my rule took care of this, because there would have been only a sendCommand if the received Command was INCREASE or DECREASE, this should suffice (in fact my rule will trigger itself, but the received command will be of Type Number, but not INCREASE/DECREASE, so when triggered from itself, it should do nothing at all).
On the contrary, your rule from posting #14 would possibly loop forever, as it will send a command, even if it did not receive INCREASE/DECREASE, but also ON/OFF or 0 to 100.
Thank you very much Udo, donât know what I did wrong, but it is working with your rule.I changed nothing in it just wrote the whole code allover again and it is working now.
it send the the whole link includingâ?status=2$s&type=textâ instead of the value of b
I want to send it as following,
192.168.0.108:5000/red3/50, instead of 50 there should be the value of variable created in the rule.
rule "dimmer Led-R"
when
Item Led_R received command
then
if (receivedCommand == DECREASE) {
Led_R.sendCommand((Led_R.state as PercentType) - 5)
}
else if (receivedCommand == INCREASE) {
Led_R.sendCommand((Led_R.state as PercentType) + 5)
}
end
I want to send the following link via http binding to my server,
192.168.0.108:5000/red3/(the value from dimmer )
can you suggest any changes?