Light on motion - Newbie with rules

Hi first time rules maker in openhab2,

I have a file “home1.rules

I have a file “home1.Sitemap":

I have a Philips hue light - Switch icon=“light” label=“Hal lamp boven” item=1EHAL
I have a fibaro Motion sensor - Switch item=0EHALMOTION label=“Motion” icon=“switch”

When I trigger motion I see the switch changing on my sitemap
I can switch the hue light on and off without any problems

I’m trying to adapt the example rule “how-to-turn-on-light-when-motion-detected-and-is-dark”


that is not working for me (nothing happens)

so I simplified it to:

rule "HalLichtAan"

when   
            Item 0EHALMOTION changed from OFF to ON
 
then   
            {
                    sendCommand(1EHAL, ON)
            }
end

Still not working

Events.log:

2016-12-12 21:51:18.496 [ItemStateChangedEvent     ] - 0EHALMOTION changed from OFF to ON
2016-12-12 21:51:18.497 [ItemStateChangedEvent     ] - zwave_device_36dce47a_node5_sensor_binary changed from OFF to ON
2016-12-12 21:51:48.922 [ItemStateChangedEvent     ] - zwave_serial_zstick_36dce47a_serial_sof changed from 38685 to 38686
2016-12-12 21:51:48.924 [ItemStateChangedEvent     ] - 0EHALMOTION changed from ON to OFF
2016-12-12 21:51:48.925 [ItemStateChangedEvent     ] - zwave_device_36dce47a_node5_sensor_binary changed from ON to OFF

What I’m I doing wrong?
Do I need to import something, do I need to restart openhab2 after I made changes??

First, order is not optional, so better set .sitemap like

Switch item=1EHAL label="Hal lamp boven" icon="light" 
Switch item=0EHALMOTION label="Motion" icon="switch"

Second, what’s your item definition like?

Third, it’s better not to use the action sendCommand(item,value) but the method item.sendCommand(value), so:

rule "HalLichtAan"
when   
    Item 0EHALMOTION changed from OFF to ON
then   
    1EHAL.sendCommand(ON)
end

Are you sure your motion detector gets set back to OFF? If not the rule won’t fire again after the first time.

Hi sorry for my late response.

Most of my items are auto generated

On my site map I have a switch representing my motion detector
When it detects movement the switch on de sitemap goes on and after a minute or so it goes off

I’m new to this and maybe I’m missing something small or I miss the concept.

Way is order on the site map important? Can’t I have a rule that uses the motion sensor without it being present on the sitemap?

Below the total content of my item, sitemap and rule file

My *.item file

Group ALLE
Group gLampen (ALLE)
Group gLampenStaan 
Group gLampenHal
Group:Switch:OR(On,OFF) gLampen "alle lampen" (all)
Group:Switch:OR(On,OFF) gLampenStaand "alle staande lampen"

My *.sitemap

sitemap home1 label="Hoofd Menu"
{ 
        Frame label="Huiskamer" {
		        Switch item=0EHALMOTION label="Motion" icon="switch"
				Switch item=gLampen label="alle lampen" icon="switch" mappings=[OFF="uit", ON="aan"]
				//Switch item=gLampenStaand label="alle staandelampen" icon="switch" mappings=[OFF="uit", ON="aan"]
                //Switch icon="light" label="Staande lamp 1" item=1ESLAMP1
                Switch icon="light" label="Staande lampen" item=gLampenStaand
                Switch icon="light" label="Eettafellamp" item=1EEETLAMP
                Switch icon="light" label="Plafondlamp" item=1EPLALAMP
        }
        Frame label="Achterkamer" {
                Switch icon="light" label="Plafondlamp" item=1ELACHTER
                Slider icon="light" label="Plafondlamp" item=1ELACHTER
        }
        Frame label= "Hal" {
                Switch icon="light" label="Hal lamp beneden" item=0EHAL
				Switch icon="light" label="Hal lamp boven" item=1EHAL
        } 
        Frame label= "Keuken" {
                
				}
        Frame label= "Slaapkamer" {
                
            
        }
}

My *.rules file

rule "HalLichtAan"
    when   
            Item 0EHALMOTION changed from OFF to ON
			     
	 then   
            {
                    sendCommand(1EHAL, ON)
            }
    end

What @Udo_Hartmann means is that the parts of a given line on the sitemap matters.

Switch icon="light" label="Hal lamp boven" item=1EHAL

is invalid syntax. You have to put the elements in the correct order. However, I’m not certain that is true any more. The fact you see anything indicates that may not be true any more.

Switch item=1EHAL label="Hal lamp boven" icon="light"

Absolutely. You do not have to put your Items on a sitemap to access them in rules.

You are trying to use Items in your sitemap that do not exist in your .items file. Are these Items that were created using PaperUI or Habmin? Presumably so.

The curly brackets on in the rule are not needed.

Add a log statement to the rule and watch openhab.log to verify the rule is triggering. It should be.

Use 1EHAL.sendCommand(ON) instead of the Action.

Hi,

Still struggling whit a simple rule

    rule "HalLichtAan"

    	when   
            Item 0EHALMOTION changed from OFF to ON
	    then   
          logInfo("logLights","light aan in hal 2")
          1EHAL.sendCommand(ON)  
		  
     end

I added the line " logInfo(“logLights”,“light aan in hal 2”)" hoping to find somthing in the openhab.log file

stopped openhab2 and started with /opt/openhab2/start_debug.sh
Still no trace that the rule is executed.

This is my first rules, so I have no idea if i’m going the right way?

If the rule isn’t triggering it most likely means that the motion sensor is not changing from OFF to On. Try loosening the trigger to just “changed” or “received update” and add an if statement to the rule to check if it is ON. Then work backwards to make the trigger more restrictive once you know what is happening.

I solved the problem, Item names cannot start with a number.

instead of item “1EHAL” i changed it to “E1HAL”

Now its working

On to the next rule

That seems like basic info missing from documentation on Item Name ?
http://docs.openhab.org/configuration/items.html

Yes, i remembered from another script languages (like powershell), that beginning a variable with a digit is a no go

How about : (colon) in a name and the use of rules?

i’m still learning