[SOLVED] Update Switches with HTTP-Binding

Hello all,
I’m a pure beginner for using OpenHab, and it would be really great, if anybody can help me for the following topic:

My platform is a Raspberry Pi 3 - The openHab Version is 2.4

I have a running web-Server on a Windows-PC, which controls my LCN-bus - with an own written LCN-bus communication (so I cannot use the LCN-binding)

I created a REST-Api, so the idea is to use the HTTP-binding in openHab.

As a first test I created a switch with the following entry in an item-file:

This is the sitemap:
image

This works!! - but:
The problem is, that I want to update the switch to the current state of the real-lamp!

The documentation says, that I have to use an “in” bounding.
To try that out I created “Teststring”, which I want to update with the result of the PHP-call.

I think I have to use “ON” and “OFF” as values, because my PHP-call delivers 0 and 1 I created a map-file:
image

The Problem is, that I’m getting error Messages in the “openhab.log” file:

So who can help me for the following Questions::
-Why am I getting Errors by using the Map-file even the needed entries seem to be part of the file?

  • What is the correct solution to update the Switch in openHab with the correct state of the lamp?
  • How can I optimize the regular updates with a Minimum of HTTP-traffic?

Thanks really a lot for your support!!

Your map appears to be reversed.

Should be:

Off=0
On=1
...

See https://www.openhab.org/addons/transformations/map/#map-transformation-service

Hello namraccr,

it’s really great to see, that you try to help me - even we don’t know each other!
Thanks really a lot for doing that!

Unfortunately, I recognized, that my description of the problem was not correct… :frowning_face:

So I updated my Topic…

Definitively, the PHP-call delivers a “1” or a “0”, I can see that also by using the HTTP-Link in a browser.
But the MAP-file does not find this “1” - even I meanwhile added both possibilities for a map from 1 to ON.

Do you have any ideas, what’s happening here? Is there any possibility to debug that problem?

Thanks and best regards
Thomas

I found the problem!!

The problem is, that the result of the php-call delivers a BOM (Byte Order Mark) for the UTF-8 char/string.

It seems, that the mapping table cannot handle that!!

I‘m now using a REGEX expression, which filters these chars out…

Thanks and best regards
Thomas