EXEC Binding - Pilight commands dont work

Thanks for the hint, i read it but i didnt understand it, is it realy that complicate to create a switch ? I realy need a rule to get that switch to work ?

My idea was… create a thing called Powerswitch-Shelf , and in that i create 2 items for ON and OFF, or iam thinking wrong ?

Why do you want to have two switches for one device toggle? Think of it like physical switch. it is just one switch, but two states ON and OFF.

So, for the start, just create one item:

Switch MyPilightSwitch	"Pilight Schalter"	{exec=">[OFF:pilight-send -p pollin -s 5 -u 4 -f] >[ON:pilight-send -p pollin -s 5 -u 4 -t]"}

perhaps you have to make sure, that pilight-send can be started without directory, or you just add it (assuming you’re using openHABian and pilight-send is compiled in ~):

Switch MyPilightSwitch	"Pilight Schalter"	{exec=">[OFF:/home/openhabian/pilight-send -p pollin -s 5 -u 4 -f] >[ON:/home/openhabian/pilight-send -p pollin -s 5 -u 4 -t]"}

CAREFUL

This one is exec1-syntax it won’t work with exec2 - please see below for more explanation on this!

1 Like

Thx binderth, we are getting closer, yes realy makes no sense to have to items for hat switch.

Mhh didnt worked , testet it with the full path to pilight send.

works like a charm in bash
/usr/local/bin/pilight-send -p pollin -s 9 -u 8 -t
/usr/local/bin/pilight-send -p pollin -s 9 -u 8 -f

Is there a log for checking - checked /opt/openhab2/userdata/logs , but nothing to find regarding the command execution.

I cant use that item in the Paper UI but shows up in HUBPanel , is there a thing needed to show up, what should i wrote in that things file to get it combind to my item ?

sorry for that silly questions, still a beginner :slight_smile:

greets ben

first of all: you don’t need anything for a item. It’s just there. especially handy if you need a “proxy item”, which just stands there as a variable - but doesn’t have an effect on anything. These items don’t have a binding definition in braces.
If you want to use a item with a binding you have to tell in the item definition the binding configuration in braces.

so. Some bindings need Things for items (most 2.x bindings need one).
The exec-binding doesn’t need one <= CAREFUL: This is false - see below for more info.

So, next step is looking into the logs, if you’re using openHABian, they’re here:

  • /var/log/openhab2/events.log // basically, everything on the eventbus is in here
  • /var/log/openhab2/openhab.log // here goes all INFO, WARNings, ERRORs, …

look in openhab.log and you’ll find something, why it didn’t work.

tried that live log in console with log:tail.

Shows only:
2:55:57.060 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘MyPilightSwitch’ received command ON
22:55:57.073 [INFO ] [smarthome.event.ItemStateChangedEvent] - MyPilightSwitch changed from OFF to ON

So no error, but still dont turn on and off , thats confusing.
in my default.items stands only:
Switch MyPilightSwitch “Pilight Schalter” {exec=">[OFF:/usr/local/bin/pilight-send -p pollin -s 9 -u 8 -f] >[ON:/usr/local/bin/pilight-send -p pollin -s 9 -u 8 -t]"}
Switch MyPilightSwitch2 “Pilight Schalter2” {exec=">[OFF:pilight-send -p pollin -s 9 -u 8 -f] >[ON:pilight-send -p pollin -s 9 -u 8 -t]"}

hmm. ok, this tells you, that the openHAB-item was changed and there was no ERROR while trying to execute. Then there’s something within your system configuration
There’s a pretty cool thread from Rich, please go there first:

if you’re still stuck, of course you can come back here anytime!

@bestgrafix @binderth I think this is the openhab 1 thing definition. So to used this kind of configuration install the legacy binding.

If you use Openhab 2 and the EXEC Binding 2 please follow the example.
When it works you can try to optimize, but i am not aware that it works as you like it to work.

Changes with the next version off the exec binding will reduce files and overhead and bring back openhab 1 binding like behavior, but for now the example is how it works and how you may get error logs to be able to traces problems.

I just did the test installing the legacy exec binding and it works as you like, no thing defining the command for on and off in the item. Before it did not.
So this is the legacy binding configuration and not the openhab 2 binding configuration.

1 Like

hmmm. I know, I messed around with the exec2-binding a year ago - but in my config, I’m not using exec1 it seems:

So, I’m curious, why the syntax works with me…? :thinking:

update:
Now I know! :wink: The items do nothing at all (as @Josar suggested correctly).
What I did obviously is to use “executeCommandline” in a rule, whenever an item changes (I’m even commented it in the rule itself!) :

rule "USB Hausnummer an/aus"
when
	Item USB_EG_Windfang_01 changed
then
	// Wegen exec 2.0 binding Syntax!
	if(USB_EG_Windfang_01.state == OFF) { executeCommandLine("/home/openhabian/usbstrom.sh 0 f 1") }
	if(USB_EG_Windfang_01.state == ON) { executeCommandLine("/home/openhabian/usbstrom.sh 0 o 1") }
end

With that comment I remember now: I was fed up with the complicated, warped exec2-thing configuration and so I did that Workaround. But I’m glad to hear that is taken care of in a new version of exec2

Perhaps this is a little better rule :wink:

The rule is thus also executed with the status NULL.
Status NULL is usually not available, since you have a persistence …

Try it, I’m not sure that the Syntax is 100% correct :wink:

rule "USB Hausnummer an/aus"
when
	Item USB_EG_Windfang_01 received command
then
	if(receivedCommand == OFF && USB_EG_Windfang_01.state != OFF) { executeCommandLine("/home/openhabian/usbstrom.sh 0 f 1") }
	if(receivedCommand == ON && USB_EG_Windfang_01.state != ON) { executeCommandLine("/home/openhabian/usbstrom.sh 0 o 1") }
end
1 Like

Thanks for your ideas. indeed my rule is a bit more complex, as I also read the status of each of the four USB-controlled power outlets and as the outlet has some minor flaws like it not always correctly toggles power and all… :wink:

1 Like

Thanks for all the help, got it to work, uninstalled EXEC Binding 2.X and installed version 1, now its working :slight_smile:

The command worked with the complete path to pilight-send and without.

2nd Question, i got Homematic IP at thome and use the HTTP Request to push the values in Pimatic, can i do that witth the HTTP Request Binding and how can i create a Diagramm in the HABPanel ?

1 Like

re Homematic IP: I don’t know this one and pimatic…

What I do now is diagrams in HABPanel. They are easy:

  1. configure persistence
  2. open up HABPanel and add a Dashboard and insert a “Chart” widget.
  3. use type RRD4j or n3-line-chart
  4. if n3-line-chart choose Service Provide (like ‘mysql’)
  5. configure Axis if needed and lastly
  6. insert your items as Series

Thanks for the info :slight_smile: I will try to setup the Persistence up - but looks complicated to me :wink:

I only want to draw a chart with temperature values , humidity and power consumption. Power consumption i already have as item from the tp link smart home binding (HS110 power plugs)

The Temp uns Humudity (values from homematicip-rest-api) i need to import , in pimatic it worked with a http request und push it in a variable, which would be an item in OpenHab2 i guess.

ah. ok - That’s pretty straight forward (both persistence and calling an API)

persistence: Just add one of your liking and configure in the .persistence configuration, which items should be persisted when => https://docs.openhab.org/configuration/persistence.html

calling an API: add the http-binding (https://docs.openhab.org/addons/bindings/http1/readme.html) and then you can add items with the API-calls as configuration:

Number Temperature "Temperature [%.1f °C]"   { http="<[http://YOURHOMEMATICIPURL)]" }

but i have to convert the string first, the api delivers me the devices in a list and i have to cut the values out example ?

3014F711A0000E970992A398 HmIP-STH Temperatur- und Luftfeuchtigkeitssensor lowbat(False) unreach(False) rssiDeviceValue(-57) rssiPeerValue(-64): actualTemperature(18.2) humidity(48)

Thats one line and i need only the value from acutal Temperature
python3 ./homematicip_cli.py --list-devices > hip-devics.log
tail hip-devics.log | grep ‘3014F711A0000E970992A398’ | grep -o -P ‘(?<=actualTemperature().*(?=) )’

then i get exact 18.2 and that value i need to get in to openhab, perhaps the HTTP Binding is not the right one?

You can use all kinds of “transformation” for parsing the payload. Easiest would be, if you can configure the homematic for a JSON payload. But Regex works also:

https://docs.openhab.org/addons/transformations.html

Number Temperature "Temperature [%.1f °C]"   { http="<[http://YOURHOMEMATICIPURL):<refreshintervalinmilliseconds>:<transformationrule>]" }
http="<[http://YOURHOMEMATICIPURL:60000:REGEX(.*\"actualTemperature\((.*)\).*)]"

(thatone is untested and I’m not the REGEX-expert. but I remember, my CCU2 having JSON already, so homematic IP should also have JSON - which would be easier to parse)

Number Temperature "Temperature [%.1f °C]"   { http="<[http://YOURHOMEMATICIPURL):<refreshintervalinmilliseconds>:<transformationrule>]" }
http="<[http://YOURHOMEMATICIPURL:60000:JSONPATH($.actualTemperature)]"

Problem is that Homematic IP has not a official API like Homematic, the python script emulates the smartphone functions.

ok - then you have to see, if my Regex-skills were good enough! :wink:

Installed the mysql peristent but connection dont work, did exact things from the tutorial:

22:31:00.282 [WARN ] [ysql.internal.MysqlPersistenceService] - mySQL: No connection to database. Can not persist item ‘Test_HumidityMYSQL (Type=NumberItem, State=92)’! Will retry connecting to database when error count:0 equals errReconnectThreshold:0
22:31:00.300 [ERROR] [ysql.internal.MysqlPersistenceService] - mySQL: Failed connecting to the SQL database using: driverClass=com.mysql.jdbc.Driver, url=jdbc:mysql://192.168.1.108:3306/openhab, user=openhab, password=*********************
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

mysql.cfg
the database url like ‘jdbc:mysql://:/’ (without quotes)
url=jdbc:mysql://192.168.1.108:3306/openhab

the database user

user=openhab

the database password

password=****************************

most likely you don’t have permission to connect to the MySQL database. This can have various reason, please have a look (my guess is 5 or internal restrictions) - Do you run your MySQL-Server on your openHAB2-server or externally?

If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException:
Communications link failure, then it means that the DB isn’t reachable at all. This can have one or more of the following causes:

  1. IP address or hostname in JDBC URL is wrong.
  2. Hostname in JDBC URL is not recognized by local DNS server.
  3. Port number is missing or wrong in JDBC URL.
  4. DB server is down.
  5. DB server doesn’t accept TCP/IP connections.
  6. DB server has run out of connections.
  7. Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

To solve the one or the other, follow the following advices:

  • Verify and test them with ping.
  • Refresh DNS or use IP address in JDBC URL instead.
  • Verify it based on my.cnf of MySQL DB.
  • Start the DB.
  • Verify if mysqld is started without the --skip-networking option.
  • Restart the DB and fix your code accordingly that it closes connections in finally.
  • Disable firewall and/or configure firewall/proxy to allow/forward the port.