Exec (or the documentation) makes me go up the walls - now with code to comment

  • Platform information:
    • Hardware: pi 3
    • OS: raspbian
    • Java Runtime Environment: what came with raspbian
    • openHAB version: openhab2
  • Issue of the topic:

Hi folks,
so after countless trials setting up my system I got openhab2 up and running.
But the documentation or the functionality of the bindings I’ve tried so far is driving me insane. I’m maybe a noob in Linux but I’d not consider myself afraid or inexperienced with computers or even a little programming. So for the last few days I was trying to get my 433mHz power sockets to work with pilight. Without success so far. I managed to set up the exec 2.0 things by paper UI for on and off and was able to operate them by classic UI. Which means that the commands are correct and working, right?

But I couldn’t manage it to set up a switch for basic UI that was working.
There are dozens of community threads and tutorials around the web which none of them shows similarities (due to countless different uses). But hey, I’m just looking for a switch configuration that combines the things “command_on” and"command_off" to a working switch. No chance to find an easy to follow guidance.

I understand that the opportunities of openhab2 are offering unlimited variety but I also think that the documentation should offer some easy receipts to follow. I was not afraid to start with openhab2, even I knew that it is not working out of the box but what I find in the web in terms of tutorials and documentation is too appliance specific or tries to cover all the opportunities but giving no helpful advice for a beginner. I’ll give some examples of how my things, items and sitemap looks like later. Hope someone can give me some support. Right now I’m too frustrated…

So here my (beginners) approach that i extruded from various community discussions:

Things:

//Dose_1
Thing exec:command:dose_1_on [ command=“sudo pilight-send -p quigg_gt7000 -i 77 -u 1 -t”, interval=0, autorun=true ]
Thing exec:command:dose_1_off [ command=“sudo pilight-send -p quigg_gt7000 -i 77 -u 1 -f”, interval=0, autorun=true ]

Items:

//Schalter_Dose_1
String dose_1 “Dose 1” [ “Switchable” ] { channel=“exec:command:dose_1_on”, channel=“exec:command:dose_1_off”}

Sitemap:

//Schalter_Dose_1
Switch item=dose_1 mappings=[ “ON”=“ON”, “OFF”=“OFF” ]

welcome :slight_smile:

Ok, before we “troubleshoot” your exec binding config, I have a question: did you try to use the “native” pilight Binding ? (http://docs.openhab.org/addons/bindings/pilight1/readme.html)

If the native binding doesn’t work for you, you can try with the exec binding.
From a quick look, your Item is wrongly defined
I am not 100% sure because I don’t use either (exec and/or pilight) bindings

Actually - no.
Because i’d like to keep the system setup within one location.
Means i don’t want to do a system setup in Pilight and then use it for system setup in openhab2.
I’d like to keep all the system setup within openhab2 only. If possible with reasonable effort.

There are mulitple problems with your item definition:

  1. It is incorrect, since you have not specified the channel that you want to link to. Typically you will want to use the “run”-channel (and link this to a Switch item).

  2. You have linked both your ON and OFF commands to the same item (Switch), meaning that you are likely to send both commands at the same time leading to unpredictable behavior (depending on which command is executed first)!

I think you need to use the following item setup:

Switch dose_1_on “Dose 1 ON” 		[ “Switchable” ] 	{ channel=“exec:command:dose_1_on:run” }
Switch dose_1_off “Dose 1 OFF” 		[ “Switchable” ] 	{ channel=“exec:command:dose_1_off:run” }

So, far so good (or at least better)…

To have only one switch in your sitemap (that you can toggle between ON and OFF to control you light) you will need to create yet another item that is not bound to any physical device, like this:

Switch dose_1 "Dose 1" ["Switchable"]

This is then the item that you put on your sitemap.

Now, the only thing that remains is to connect the unbound Switch item to the two Switches that control you pilight device, and this must be done through a set of rules.

rule "Turn light on"
when
  Item dose_1 changed to ON
then
  // Execute command script to turn light ON
  dose_1_on.sendCommand(ON)
end
rule "Turn light off"
when
  Item dose_1 changed to OFF
then
  // Execute command script to turn light OFF
  dose_1_off.sendCommand(ON)
end

Granted, this is a bit elaborate, but it should work…

Just a question, why not use a simple switch and a rule with the executeCommandLine action?

I just use the Exec Binding for some sensors which are queried by script.

Thanx Kjetil! This is an explanation i can follow.
Wonder why the exec binding manual (or others) do not offer one simple complete example for easier understanding.

That sounds interesting. Giving it a try.
I know that exec binding is kinda overkill for this action but i really want to learn about it on a simple example (haha, failed) since it seems to be the most universal one.

Just wrote it, without testing. :wink:

Some details need to be checked, the path of the script, the user openhabian needs execute rights to be granted, etc.
But basically, that’s it.

item:

Switch simpleswitch "a simple switch"

rule:

rule "simple rule" 
when 
   Item simpleswitch received command
then
   if (simpleswitch.state == ON) 
   {
      executeCommandLine("switchon.sh")
   }
   else if (simpleswitch.state == OFF) 
   {
      executeCommandLine("switchoff.sh")
   }
end

It does, it just wasn’t an example that exactly matched your use case. These lower level bindings are hard to document and hard to use because they are too generic to provide just one simple example that works for all use case.