Problems with exec in oh2

Not in a .sh script, in OpenHAB rules. Something like:

rule "test"
when
Item TEMP_WOHNZIMMER changed
then
TEMP_WOHNZIMMER_PROXY.postUpdate((TEMP_WOHNZIMMER.state as DecimalType))
end

You should, of course, add an item:

Number TEMP_WOHNZIMMER_PROXY

Best regards,
Davor

So I should display the proxy value?

Thanks a lot

Yes, and use that proxy item for a chart too.

Best regards,
Davor

I tried it:

default.items:

String TEMP_WOHNZIMMER_STRING "[%s]" {channel="exec:command:TEMP:output"}
Number TEMP_WOHNZIMMER2 "Temperatur Mein Zimmer [%.1f °C]" <temperature> (Temperatur)

default.rules:

 import org.eclipse.smarthome.core.library.types.DecimalType

rule "test"
when
Item TEMP_WOHNZIMMER_STRING changed
then
TEMP_WOHNZIMMER2.postUpdate((TEMP_WOHNZIMMER_STRING.state as DecimalType))
end

In the openhab.log I get:

2016-12-27 08:59:59.405 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'test': org.eclipse.smarthome.core.library.types.DecimalType

Hello!

If you are on OH2, I don’t think you need that import. It should be included by default. I don’t have access to my OH installation right now, so I can’t test it, but, could you try this syntax:

TEMP_WOHNZIMMER2.postUpdate(new DecimalType(TEMP_WOHNZIMMER_STRING.state))

Best regards,
Davor

I tried it:
default.rules:

rule "test"
when
Item TEMP_WOHNZIMMER_STRING changed
then
TEMP_WOHNZIMMER2.postUpdate(new DecimalType(TEMP_WOHNZIMMER_STRING.state))
end

openhab.log:

2016-12-27 09:27:13.081 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'test': An error occured during the script execution: Could not invoke constructor: org.eclipse.smarthome.core.library.types.DecimalType.DecimalType(long)

In the sitemap:
TEMP_WOHNZIMMER_STRING: %14.90
TEMP_WOHNZIMMER2: - °C

Sorry for the trial and error method, but, since I can’t test it myself, there is no other way to do this. The only other way I can think of is using this:

TEMP_WOHNZIMMER2.postUpdate(Double::parseDouble(TEMP_WOHNZIMMER_STRING.state))

Note: Double colon sign is not a typo.

Best regards,
Davor

No problem. You’re a big help at all

Double colon sign is ok. I know those kind of syntax.

I still get an error in my openhab.log and nothing is displayed.

2016-12-27 09:46:00.175 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'test': An error occured during the script execution: Could not invoke method: java.lang.Double.parseDouble(java.lang.String) on instance: null

Wait a second, do you have a percent sign in the String item? If you do, you can’t just convert it to number, because it contains alphanumeric character. From the earlier messages I thought you said you get a number as the result of exec command.

Best regards,
Davor

I realy don’t know.
In the sitemap there is one.
The script does not return one and in paper ui i don’t see one.

Just use Rest API and look at the state of the item. If there is a percent sign, then it should be removed before converting it to a number.

Best regards,
Davor

From the rest api:

{"link":"***:8080/rest/items/TEMP_WOHNZIMMER_STRING","state":"15.10","stateDescription":{"pattern":"%s","readOnly":false,"options":[]},"type":"String","name":"TEMP_WOHNZIMMER_STRING","label":"","tags":[],"groupNames":[]},{"link":"***:8080/rest/items/TEMP_WOHNZIMMER2","state":"NULL","stateDescription":{"pattern":"%.1f °C","readOnly":false,"options":[]},

Remove a link as soon as possible. Anybody could access your OH instance right now.

Best regards,
Davor

Thanks.
I removed it.

Really? That seems like a big step backward from the 1.x Exec binding that can update all items types.

The only thing that comes to mind is trying to use:

TEMP_WOHNZIMMER2.postUpdate(Double::parseDouble(TEMP_WOHNZIMMER_STRING.state.toString))

Btw, state of the item looks OK in the Rest API. If this doesn’t work, I’ll have to try it when I get home, so I can test it on my OH server.

Best regards,
Davor

Well, it looks like that’s the case. It was just my conclusion, not something explicitly written in the documentation. But it wasn’t working the other way.

Best regards,
Davor

It works.
The Temperature is now displayed correct.

Temperature and Humidity are now ok

But I really don’t know how to make my Switch Items 433 compatible

my oh1 item and sitemap:
default.items:

Switch SW_PS4 "Playstation 4" (Status) ["Switchable"] {exec="ON:sudo /etc/openhab2/scripts/send.sh 01101 1 1, OFF:sudo /etc/openhab2/scripts/send.sh  01101 1 0" }

default.sitemap:

Switch item=SW_PS4 label="Playstation 4" mappings=[ON="An", OFF="Aus"]

Hope anbody can help me.
I want to update this to the OH2 exec binding.

Hi there,

Is there any improvement to the Exec 2 binding planed? In my opinion, it’s a big backward step too. With the 1.x Exec binding it’s totally easy to bind such string script output to Number items. In OH2 with Exec 2 we have to use proxy items and rules?!?! I’m absolutely unhappy with this.

I’ll stay at Exec 1 then and looking forward to any improvement to the Exec 2 binding.

Best regards,
Chris