Help With First Text Rule [Solved]

i am starting to create my rules in text (trying im a beginner)

i have a light that i want too dim at certain times of day i have sorted this code

rule "Test Dim Rule"
when
Time cron "	0 10 22 1/1 * ? *"
then
if (Lamp1_Brightness >= 50) {
sendCommand(Lamp1_Brightness, 50)
}
end

When the time occurs nothing happens watching the log says this

What’s wrong with my rule :frowning:

In rules you have to use .state to reference to the state. So your rule should be more like this:

rule "Test Dim Rule"
when
    Time cron "0 10 22 * * ?"                     //year is optional
then 
    if((Lamp1_Brightness.state as Number) > 50) { //cast the state as number
        Lamp1_Brightness.sendCommand(50)          //whenever possible prefer the method over the action
    }
end

See One rule fires but not the other, why in question of .state and
http://docs.openhab.org/configuration/rules-dsl.html#sendcommand-method-vs-action in question of method vs. action.

1 Like

Thanks I will try to edit my rule see if it fixes my problem

Another hint for your further questions:
Please do not post screenshots.
You should paste&copy the relevant parts of your rules/logs/setup-files etc. AND format the pasted text as “preformated text” ( the icon with the " on top of the box in which you write/paste your question).
Reading your post will be much easier that way.

1 Like

im sorry for the screenshots its the fastest way to get the information especially for rules and items within paperui

do you mean like how i edited this post

I know of no other way besides screen shots from PaperUI. But for text rules and logs it is much easier on us if you copy and paste the text into the posting rather than screen shots.

To clarify what opus is saying. If you press one of these icons

image

you will get some code fences inserted into your posting. Paste the code or logs between the fences and all the indentation and lines will be preserved. Way easier to read, especially when reading from a phone.

The first thing to do when you are debugging Rules that do not seem to be triggering is to make the first line in the Rule be a logInfo statement. Then look in openhab.log for that statement. If you see it you know the rule is triggering but has some other problem. If you don’t then you know the problem is with the rule trigger itself.

1 Like