looking to make my first rule but honestly dont know where or how to start .
Yes i have tryed to learn from documentations and other users examples,but i have a hard time understanding them and knowing how to use the info. Secondly there seems to be different ways of doing it .
Not even sure its possible
So i hope a friendly soul will help a noob.
But what i would like is to dim my hue spots in the office at night lets say after 22 to 06. .Lights are controlled by pir ,AND pressing the light switch should make spots go to 100%.
Do you want a DSL rule? If you have no clue and have read the rules documentation, Iâm guessing yes. The rule will need to be in a rules file and placed in the rules directory of OpenHABâs conf directory
The rule takes the form of:
rule âunique rule name in quotesâ
when
some trigger condition
then
some cool stuff happens
end
So you pir reporting motion would probably be what you wanted as a trigger condition. Youâll need an item linked to the motion channel on the pir so your when would be
Item myitem changed
in the then put some logic to check the time
if (now.getHourOfDay() >= 06 && now.getHourOfDay() < 22) {
mylightdimmer.sendCommand(40)
}
so something like:
rule âunique rule name in quotesâ
when
Item myitem changed
then
if (now.getHourOfDay() >= 06 && now.getHourOfDay() < 22) {
mylightdimmer.sendCommand(40)
}
end
this is an over simple rule and you will need another to turn the spots to 100% but you get the idea.Watch the case of things rule, when, then and end are all lower case only. Item in the when is upper case âItemâ
good luck, have fun and come back when you get stuck
Maybe i need to give more info. Our house is equiped with IHC (intelligent house control) that is not really very intelligent
Pir is part of IHC and controling lights thru that.but i dont have IHC dimmers so want to use HUE spots to do dimming part.
So on/off is handled outside of Openhab.
So i would like Openhab only to handle the dimming part.,so on/off works even if openhab is down.
Does it ,make sence ?
Can OH connect to IHC? If not then you can use a cheap photocell to detect if the light is on or off. Use that input in the rule to control the dimming.
For the photo cell an ESP8266 device communicating via mqtt with OH will work well. I have this in my garage so Alexa will tell me if the garage door is closed and the light was left on.
YES there is even a very nice binding . pir does "report " into Openhab. Openhab also knows if light is on/off .I can control the on/off thru Openhab aswell.
Sounds good. Just add the correct item names to the rule example above and see if it acts as expected.
EDIT:
May want to change the trigger to specify ON else the light may want to toggle ON/OFF.
rule "unique rule name in quotes"
when
Item myitem changed to ON
then
if (now.getHourOfDay() >= 06 && now.getHourOfDay() < 22 && LightSwitch.state != ON) {
mylightdimmer.sendCommand(40)
}
else if (LightSwitch.state == ON) {
mylightdimmer.sendCommand(100)
}
end
before digging in i need to ask a few dump question
I guess lightswitch is refering to the actual âlightswitchâ âŠLightswitch is a âtoggle switchâ and not an on/off if that makes sence. Does that make a difference.
and lights are a group of 3 spots. does that change anything
That is the switch to turn the lights to 100% brightness.
This might affect how the rule behaves but give it a try and see what happens. Playing with rules there will be lots of trial and error but thatâs part of learning.
So itâs three separate bulbs, or items in OH, correct? If so then check the docâs about how to use groups or you will need to list each light inside the rule.
I will most likely not be online later so I will give you a hint on the toggle switch but try the rule first just to see what happens.
Hereâs part of a post I found and hope you find it as a good hint for solving your toggle switch issue.
var Timer tToggle = null
rule "toggle frequently"
when
Item myTriggerItem changed
then
tToggle?.cancel
if(myTriggerItem.state == ON)
tToggle = createTimer(now.plusMillis(200),[ |
myTogglingItem.sendCommand(if(myTogglingItem.state != ON) ON else OFF)
tToggle.reschedule(now.plusSeconds(2))
])
end
When the rule gets triggered (because the Item myTriggerItem changed its state), the first thing is, an existing timer is killed. The second step is, to create a new timer, but only if the current state is ON.
The timer will expire almost immediately and will toggle the Item myTogglingItem. Then the timer will reschedule itself two hours later.
Please be aware that myTogglingItem will keep its state when myTriggerItem is switched OFF, so the only thing which is switched, is the toggling!
rule "NatsĂŠnkning
when
Item ihc:controller:elko:output77659 changed to ON
then
if (now.getHourOfDay() >= 06 && now.getHourOfDay() < 1700 && LightSwitch.state != ON) {
hue:0220:0017884c7a9b:30:brightness.sendCommand(40)
hue:0220:0017884c7a9b:29:brightness.sendCommand(40)
hue:0220:0017884c7a9b:28:brightness.sendCommand(40)
}
else if (LightSwitch.state == ON) {
hue:0220:0017884c7a9b:30:brightness.sendCommand(100)
hue:0220:0017884c7a9b:29:brightness.sendCommand(100)
hue:0220:0017884c7a9b:28:brightness.sendCommand(100)
}
end
log states
2020-03-08 18:01:09.825 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model âhus.rulesâ has errors, therefore ignoring it: [102,6]: String literal is not properly closed
OK good thing to note⊠EVERY every every time you edit a rule and save it, have your terminal open and watch the log tail for the model (rules file) being loaded correctly
that means your rules files is messed up, not going to work and the system is not going to load it at all. There is a mistake in the rule
this second bit is telling you where the error is and what is wrong
you are missing a closing quote apparently
Believe it or not i have spend many hours with Openhab ,and have a decent size installation running quite nicely for more than a year with more than 100 items and things.
But you are totally right ,i have made a total rookie error .
Digging into the IHC system ,i realized that switch is actually not a toggle switch.
It is an âelectronicâ contact that is ON as long as it is pushed.,but can be setup to âmimicâ toggle behaviur. The need for a second rule ,leads me to believe ,that toggle is not optimal.
for learning purpuses i am ignoring the need to be able to increase dim to 100%.
So i am trying this
rule "Natlys"
when
Item Kontor_spots changed to ON
then
if (now.getHourOfDay() <= 06 && now.getHourOfDay() > 17 && Kontor_spots.state != ON) {
Kontor1_Dimmer.sendCommand(40)
Kontor2_Dimmer.sendCommand(40)
Kontor3_Dimmer.sendCommand(40)
}
end