[SOLVED] Openhab linking items, create a sitemap and run script when doorbell is pushed

Hello,

I’v been struggling with OpenHab for more then a week.

I’ve a orange Pi plus 2E with Rfxcom and it works with al my kaku-switches. I’ve a wireless-walswitch even from kaku. I want to push the wallswitch and then it has to turn on the light in the kitchen and livingroom. Tried to link channels but it didn’t work… Read many forums but no luck.

And if I press my doorbel it has to trigger a script that sends me a foto of whois in front of the door. The script runs fine in cli. But I cannot accomplish this. I tried rules but with no luck.

I’ve made everthing whti paper ui and habmin. But how can I create a sitemap? I’ve read many topics but i;m stuck.

I cam from domoticz

thanks,

Jeroen

https://www.openhab.org/docs/tutorial/sitemap.html

Can you post them?

Hello Vicent,

Thanks for your reply. I want to trigger a script when the doorbell is pressed:

rule "Deurbel"

when                                                                                                                                                                                          
        item "rfxcom:lighting2:ded27f2a:17077686_0:command" triggered                                                                                                                        
then                                                                                                                                                                                          
        var String Deurbel = executeCommandLine("sudo /etc/openhab2/scripts/deurbel.sh",10000)                                                                                 
end 

and this one for my wallswitch:

rule "Wandschakelaar_BG_WK"
when
  Item rfxcom_lighting4_ded27f2a_278865_command changed from OFF to ON
then
  sendCommand(rfxcom_lighting4_ded27f2a_262145_command, ON)
  sendCommand(rfxcom_lighting2_ded27f2a_14160886_1_command, ON)
end

rule "Wandschakelaar_BG_WK"
when
  Item rfxcom_lighting4_ded27f2a_278865_command changed from ON to OFF
then
  sendCommand(rfxcom_lighting4_ded27f2a_262145_command, OFF)
  sendCommand(rfxcom_lighting2_ded27f2a_14160886_1_command, OFF)
end

shouldn’t this be Channel [...] triggered ?
(or Item [...] received update)

I see some other errors also but it’s better to use VSCode to debug rules

Hello Dim,

I tried both, but no luck,
Also installed the Exec-binding but didn’t work either.
Made an Thing with exec binding and now it triggers al the time

What is this channel?
“rfxcom:lighting2:ded27f2a:17077686_0:command” is it a switch?
Not all binding accept channel triggers
Assign an item to that channel and chande the trigger to that rule

RENAME your items, you can’t know what they are by just reading your code

The other two rules have the same same. That won’t do:
We are going to use the implicit variable called receivedCommand
https://www.openhab.org/docs/configuration/rules-dsl.html#implicit-variables-inside-the-execution-block
We are also going to use the item method .sendCommand() rather than the action sendCommand(Item, Command)
https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state

rule "Wandschakelaar_BG_WK"
when
  Item rfxcom_lighting4_ded27f2a_278865_command changed
then
  rfxcom_lighting4_ded27f2a_262145_command.sendCommand(receivedCommand)
  rfxcom_lighting2_ded27f2a_14160886_1_command.sendCommand(receivedCommand)
end

What is this channel?
“rfxcom:lighting2:ded27f2a:17077686_0:command” is it a switch?

This is a switch.

Assign an item to that channel and chande the trigger to that rule

I’ve made an new item: wandschakelaar. In Configuraion > Things I linked the item to the channel command

and put the name in the rule:

    rule "Wandschakelaar_BG_WK"
    when
      Item wandschakelaar changed
    then
      rfxcom_lighting4_ded27f2a_262145_command.sendCommand(receivedCommand)
      rfxcom_lighting2_ded27f2a_14160886_1_command.sendCommand(receivedCommand)
    end

But it stil doesn’t work. Perhaps I misunderstood you.

And from my doorbell script I get an error. I gues it runs. this is the error:

20:50:22.966 [ERROR] [nhab.binding.exec.handler.ExecHandler] - An exception occu                                                                                        rred while executing '/etc/openhab2/scripts/deurbel.sh' : 'Cannot run program "/                                                                                        etc/openhab2/scripts/deurbel.sh": error=13, Permission denied'

I added openhab user to sudoers.

From you screen shot,
wandschakelaar is linked to rfxcom:lighting4:ded27f2a:278865:command and not
rfxcom:lighting2:ded27f2a:17077686_0:command

What you did is rename an item.
What is wandschakelaar? In the real world, physically?

This is my wireless doorbellbutton.

This is a physiccaly wallswitch form kaku https://www.klikaanklikuit.nl/nl/awst-8800-draadloze-wandschakelaar.html and in paper UI it’s configured like this:


When I press this switch I want the marked switches te be turned on:

I think you are getting confused between things and items.

In the thing Licht_kamer there will be channels
One off the channel will probably be command
Link an item to that channel and call the item 'Licht_Kammer_Switch`
TO turn the “Real world” switch you send the command ON to the item:

Licht_Kammer_Switch.sendCommand(ON)

For your door bell do the same thing:
Link an item called ‘Doorbell’ to the command channel of the ‘Deurbell’ thing
Then your rule trigger is:

rule "Deurbel"

when                                                                                                                                                                                          
        item Doorbell received command                                                                                                                        
then                                                                                                                                                                                          
        var String Deurbel = executeCommandLine("sudo /etc/openhab2/scripts/deurbel.sh",10000)                                                                                 
end 

And the second rule:

rule "Wandschakelaar_BG_WK"
when
    Item wandschakelaar received command
then
    rfxcom_lighting4_ded27f2a_262145_command.sendCommand(receivedCommand)
    rfxcom_lighting2_ded27f2a_14160886_1_command.sendCommand(receivedCommand)
end

But change those item names, please

Thanks for your help to understand this.

This is how the lights are being configured:

and this is the wallswitch:

and my rules looks like this:

rule "Wandschakelaar_BG_WK"
when
  Item wandschakelaar changed
then
  Licht_Kammer_Switch.sendCommand(ON)
  Licht_Keuken_Switch.sendCommand(ON)
end

it still doesn’t work. Do you have any idea what I’m doing wrong.

That is the Item label (not the Item name)
You need to use the Item name within your rules.
Try the version that Vincent posted:

He told me to :

I did here are my items:

He also posted a working rule and asked you to modify the Item names
(e.g from rfxcom_lighting2_ded27f2a_14160886_1_command to Licht_Kammer_Switch :slight_smile:)

You used Licht_Kammer_Switch as the Item Label. You need to use the Item name (not label) in the rules.

I’m sorry I didn’t understand it. Now I made new items with logical names like this:

And changed my rules like this

rule "Wandschakelaar_BG_WK"
when
  Item Wandschakelaar_Beneden changed
then
  Licht_Kamer_Switch.sendCommand(ON)
  Licht_Keuken_Switch.sendCommand(ON)
end

And now it worked. Thanks a lot both of you.

1 Like

Good well done.
Do you have a better understanding of the difference between things and items?
And the items names and labels.
You could change the items labels to something without the _ now.

Please mark the thread as solved

Yes I have. Thanks. I’m now figuring out, when I puss off both lights must go off. When I push on both lights must turn on.

Everything works fine. With this rule:

rule "Wandschakelaar_BG_WK"
when
  Item Wandschakelaar_Beneden changed
then
  Licht_Kamer_Switch.sendCommand(ON)
  Licht_Keuken_Switch.sendCommand(ON)
end

It turns on but I cann’t turn the lights off.
But now I wanna just turn on and off the same lichts. I edit the rule as shown below.

rule "Wandschakelaar_BG_WK_ON"
when
  Item Wandschakelaar_Beneden changed to ON
then
  Licht_Kamer_Switch.sendCommand(ON)
  Licht_Keuken_Switch.sendCommand(ON)
end

Rule "Wandschakelaar_BG_WK_OFF"
when
	Item Wandschakelaar_Beneden changed to OFF
then
	Licht_Kamer_Switch.sendCommand(OFF)
	Licht_Keuken_Switch.sendCommand(OFF)
end

when I use just the firts rule:

rule "Wandschakelaar_BG_WK_ON"
when
  Item Wandschakelaar_Beneden changed to ON
then
  Licht_Kamer_Switch.sendCommand(ON)
  Licht_Keuken_Switch.sendCommand(ON)
end

But when I add the second rule it doesn;t work. I’ve even made two different rules, but with the same result.

rule

Use VSCode :slight_smile: (and check your logs)