First ever rule ,need guidance

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

I realised i need to dig in my IHC system a bit more first…this is paused…

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.

Is the short ON signal better ?

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

But no errors in log,and rules does not work.

Your if() condition is a bit suspect. The hour needs to be less than 6 and more than 17 at the same time.
The rule will only run when your Item changes to ON but will only do something when it is not ON.

Thx for your input.

i understand time issue but.not sure hov to adress . but will only do something when it is not ON.

I don’t know what you’re trying to achieve …

The rule will run when the Item changes to ON
Perhaps that’s not right - when do you want the rule to run?

A few milliseconds after the rule begins to run …

Your if() only evaluates to “true” (and so runs the code in curly brackets) if your Item is now not-ON. It won’t be of course, because you only get here if its just changed to ON.

It’s obviously not the right test, but I don’t know what you want to test for - if anything.

Maybe put into words your objective.

@BDE

Better use the following in your rule:

   when 
   Item Kontor_spot received command ON
if (now.getHourOfDay() >= 17 && now.getHourOfDay() > =6  && Kontor_spots.state != ON) {

Would this be after 5 pm and before 6 am in the morning…

No.

You have to use OR.

OR is || in rules.

very briefly

I want to dim my HUE spots in the evening .

So when they are on i want them to be dimmed…So action need to happen after they are on, otherwise they wont dim (hue)

Damn i just dont get it…

Why OR ?

I guess both “requirements” needs to be fullfilled…

Is there a number that is less than 6 and simultaneously greater than 17?

hahaha …I have so much to learn…

Okay, you’ve got to really think about the rule trigger here.
You’d want to run your rule when evening begins, fairly obviously.
But to do as asked you would also want to run the rule whenever the spots change in any way. So that if they turn on, they get forced to 40%, If anyone turns them up or down, set back to 40%.

You’d want two conditions inside your rule -
“Is it evening?” so that the rule does not interfere at other times.
“are the spots on?” so that the rule does not interfere if they are off - they can be turned off even during evening

If that’s not exactly what you want (do you really want to stop people turning them up or down during the evening?) then you have to modify your requirement.

Setting out what you are trying to do clearly goes a long way to writing a rule.

Let me start from the back…

Setting out what you are trying to do clearly goes a long way to writing a rule.
Absolutely… correct .and your input is very valuable…

You’d want to run your rule when evening begins, fairly obviously.

correct i just set it to 5 oclock for testing ,when live it will be changed to bedtime

But to do as asked you would also want to run the rule whenever the spots change in any way. So that if they turn on, they get forced to 40%, If anyone turns them up or down, set back to 40%.

Ok i need to explain more. i want to dim the light at bedtime ,so bathroom visits will be dimmed.
On top of that i would like the oppertunity to be able to push lightswitch and increase to 100% if needed

You’d want two conditions inside your rule -
“Is it evening?” so that the rule does not interfere at other times.CORRECT
“are the spots on?” so that the rule does not interfere if they are off - they can be turned off even during evening also CORRECT

If that’s not exactly what you want (do you really want to stop people turning them up or down during the evening?) then you have to modify your requirement.

Yes as stated above .Turning up IS relevant .turning down not so much,since its for “night light”

does that make sence ?

BTW ligths are controlled by PIR ,so on/off are automatic and only when it is dark

Okay, let’s see if I can restructure that.

At bedtime, if the and only if the lights if are on, dim to 40% (what if they are already less than 40%?)

If someone comes along after bedtime and turns them up, down, off, or on - don’t interfere.

That seems to be it.

Trigger a rule at bedtime,
if the light is on set to 40%

(what if they are already less than 40%?)

 Very simple question they are not. they have never been dimmed other than for testing..and i dont see why they should other than after bedtime..

If someone comes along after bedtime and turns them up, down, off, or on - don’t interfere.

Exactly

That seems to be it.

Trigger a rule at bedtime,
if the light is on set to 40%

yes that was my idea… But how to do that is my problem…

Add Jython and the helper libraries with…

Then copy over the script from…

… and configure the metadata in your Items. There’s an example very much like what you ware trying to do.

Trigger a rule at bedtime.
That’s a time-based trigger, uses a cron expression

if the light is on set to 40%
It’s not that difficult, but we can break it down

if the light is on

if ( mylightItem.state == ON ) {
do stuff
}

BUT … it’s a dimmer, the state is numeric

if ( mylightItem.state as Number > 0 ) { // one way to test a dimmer for on
do stuff
}

if the light is on set to 40%

You can do that bit

thank your for your help.

I will look into it,at first chance