[SOLVED] Need to update state of web relay via xml

  • Platform information: Raspberry Pi 3
    • OS: openhabian
    • Java Runtime Environment: openjdk version “1.8.0_152”
    • openHAB version: [master]v1.4.1-433(ee99445)
  • Issue of the topic: Good morning and sorry for my poor english. Ive looked for an answer without luck. Here is my problem…ive a web relay and i can query it with url http://192.168.1.6/status.xml i can see this:
<response><led0>0</led0><led1>0</led1><led2>0</led2><led3>0</led3><led4>0</led4><led5>0</led5><led6>0</led6><led7>0</led7><btn0>up</btn0><btn1>dn</btn1><btn2>up</btn2><btn3>up</btn3><btn4>up</btn4><btn5>up</btn5><btn6>up</btn6><btn7>up</btn7></response>

When i activate a light, the btnX go to “dn” state…
Now, for example, i’ve a light called “Luce dell’ingresso” that is activate via manual button also…how can i update the status (icon and state) of this light (btn6) in OH and BasicUI when it change from a normal fisical button?
This is my .sitemap

Switch item=PT_Luce_Ingresso label="Luce dell'ingresso" icon="light" mappings=[OFF="OFF", ON="ON"]

This is my .items

Switch PT_Luce_Ingresso "Luce dell'ingresso" (gPTCorridoio,light) ["Switchable"] 

I was thinking to use http bindings and i try this in default items

Switch PT_Luce_Ingresso "Luce dell'ingresso" (gPTCorridoio,light) ["Switchable"] {http="<[Domo2:3000:XPATH(/response/btn6/text()):MAP(onoff.map)]"}

but i dont know how use it and also in LOG i receive a lot of error like

org.openhab.core.transform.TransformationException: transformation throws exceptions	at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [212:org.openhab.core.compat1x:2.3.0]	at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:194) [224:org.openhab.binding.http:1.12.0]	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [212:org.openhab.core.compat1x:2.3.0]	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [212:org.openhab.core.compat1x:2.3.0]2018-12-26 20:51:51.475 [WARN ] [ab.binding.http.internal.HttpBinding] - Transformation 'XPATH(/response/btn6/text()):MAP(onoff.map)' threw an exception. [response=<response><led0>0</led0><led1>0</led1><led2>0</led2><led3>0</led3><led4>0</led4><led5>0</led5><led6>0</led6><led7>0</led7><btn0>up</btn0><btn1>dn</btn1><btn2>up</btn2><btn3>up</btn3><btn4>up</btn4><btn5>up</btn5><btn6>up</btn6><btn7>up</btn7></response>]

You cannot use 2 transformations at once.
You will need a proxy item and a rule:

String PT_Luce_Ingresso_String "Luce dell'ingresso" (gPTCorridoio,light) ["Switchable"] {http="<[Domo2:3000:XPATH(/response/btn6/text())]"}
Switch PT_Luce_Ingresso "Luce dell'ingresso"

rule

rule "PT Luce Ingresso transform"
when
    Item PT_Luce_Ingresso_String changed
then
    if ( PT_Luce_Ingresso_String.state == UNDEF !!  PT_Luce_Ingresso_String.state == NULL) return;
    PT_Luce_Ingresso.postUpdate(transform("MAP", "onoff.map", PT_Luce_Ingresso_String.state.toString)
end
1 Like

Many thanks for the reply…ive write your code in my OH and return this error

2018-12-26 22:02:24.353 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.rules' has errors, therefore ignoring it: [3,5]: no viable alternative at input 'PT_Luce_Ingresso_String'[5,49]: missing ')' at '!'[5,90]: mismatched input ')' expecting 'end'

In the onoff.map ive wrote

ON=dn
OFF=up
dn=ON
up=OFF

And in http.cfg

# configuration of the first cache item
Domo2.url=http://192.168.1.6/status.xml
Domo2.updateInterval=3000

Sorry im a noob :slight_smile:

Try again
Do NOT copy and paste…
Type it up.

rule "PT Luce Ingresso transform"
when
    Item PT_Luce_Ingresso_String changed
then
    if (PT_Luce_Ingresso_String.state == UNDEF ||  PT_Luce_Ingresso_String.state == NULL) return;
    PT_Luce_Ingresso.postUpdate(transform("MAP", "onoff.map", PT_Luce_Ingresso_String.state.toString))
end

Ok ive typed all…there is a missing ) before the end statement…
but, ive this WARN…so is only a warn but i wanto to understand…THANK YOU VERY MUCH!

2018-12-26 22:17:44.004 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'default.rules' has errors, therefore ignoring it: [3,2]: no viable alternative at input 'PT_Luce_Ingresso_String'

Did you change the items as above?

Yes…after mod the light dont activate anymore.
I use “Google home” too…the “Switchable” must be in String?
Now my rules is

rule "PT Luce Ingresso transform"
when
        PT_Luce_Ingresso_String changed
then
        if (PT_Luce_Ingresso_String.state == UNDEF || PT_Luce_Ingresso_String.state == NULL) return;
        PT_Luce_Ingresso.postUpdate(transform("MAP","onoff.map",PT_Luce_Ingresso_String.state.toString))
end
rule "LUCE INGRESSO ON"
when
        Item PT_Luce_Ingresso received command ON

then
        sendHttpGetRequest("http://192.168.1.2:8083/command=set_active?605")
end

rule "LUCE INGRESSO OFF"
when
        Item PT_Luce_Ingresso received command OFF
then
        sendHttpGetRequest("http://192.168.1.2:8083/command=set_deactive?605")
end

The item is

String PT_Luce_Ingresso_String "Luce dell'ingresso" (gPTCorridoio,light) ["Switchable"] {http="<[Domo2:3000:XPATH(/response/btn6/text())]"}
Switch PT_Luce_Ingresso "Luce dell'ingresso"

The sitemap is

  Switch item=PT_Luce_Ingresso label="Luce dell'ingresso" icon="light" mappings=[OFF="OFF", ON="ON"]

The LOG is (truncated) [why the sistem doesnt recognize change of state? the String change only this time]

2018-12-26 22:33:22.436 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso_String changed from NULL to up
2018-12-26 22:33:25.660 [ome.event.ItemCommandEvent] - Item 'PT_Luce_Ingresso' received command ON
2018-12-26 22:33:25.682 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso changed from NULL to ON
2018-12-26 22:33:28.441 [ome.event.ItemCommandEvent] - Item 'PT_Luce_Ingresso' received command OFF
2018-12-26 22:33:28.457 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso changed from ON to OFF

BUT the light dont activate anymore…

Change that:

        PT_Luce_Ingresso.postUpdate(transform("MAP","onoff.map",PT_Luce_Ingresso_String.state.toString))

to

        PT_Luce_Ingresso.sendCommand(transform("MAP","onoff.map",PT_Luce_Ingresso_String.state.toString))
1 Like

Nothing to do…ive tried some change but nothing…cant understand :frowning:

Ty a lot for your patience

UPDATE…NOW if i activate and deactivate the light from button the LOG write

2018-12-26 22:59:11.204 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso_String changed from up to dn
2018-12-26 22:59:20.405 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso_String changed from dn to up

BEATIFUL…but now why the button on sitemap doesnt activate?

Seems that the rule “LUCE INGRESSO ON” received command but dont execute the “then”

 rule "PT Luce Ingresso transform"
when
        PT_Luce_Ingresso_String changed
then
        if (PT_Luce_Ingresso_String.state == UNDEF || PT_Luce_Ingresso_String.state == NULL) return;
        PT_Luce_Ingresso.sendCommand(transform("MAP","onoff.map",PT_Luce_Ingresso_String.state.toString))
end
rule "LUCE INGRESSO ON"
when
        Item PT_Luce_Ingresso received command ON
then
        sendHttpGetRequest("http://192.168.1.2:8083/command=set_active?605")
end

The LOG

2018-12-26 23:09:19.443 [ome.event.ItemCommandEvent] - Item 'PT_Luce_Ingresso' received command ON
2018-12-26 23:09:19.459 [vent.ItemStateChangedEvent] - PT_Luce_Ingresso changed from OFF to ON

UPDATE…if a cancel the “PT Luce Ingresso transform” rule, the Switch “Luce dell’ingresso” work…

SOLVED!!! ahahahh :smile:
The problem is the “Item” missing before “PT_Luce_Ingresso_String”…

rule "PT Luce Ingresso transform"
when
        PT_Luce_Ingresso_String changed

THANK YOU A LOT TO ALL FOR THE PATIENCE
So…for all the others who need…
This is the correct files…
ITEMS

String PT_Luce_Ingresso_String "Luce dell'ingresso" (gPTCorridoio,light) ["Switchable"] {http="<[Domo2:3000:XPATH(/response/btn6/text())]"}
Switch PT_Luce_Ingresso "Luce dell'ingresso"

RULES

rule "LUCE INGRESSO ON"
when
        Item PT_Luce_Ingresso received command ON
then
        sendHttpGetRequest("http://192.168.1.2:8083/command=set_active?605")
end

rule "PT Luce Ingresso transform"
when
        Item PT_Luce_Ingresso_String changed
then
        if (PT_Luce_Ingresso_String.state == UNDEF || PT_Luce_Ingresso_String.state == NULL) return;
        PT_Luce_Ingresso.sendCommand(transform("MAP","onoff.map",PT_Luce_Ingresso_String.state.toString))
end

SITEMAP

Switch item=PT_Luce_Ingresso label="Luce dell'ingresso" mappings=[OFF="OFF", ON="ON"] icon="light"

onoff.map

dn=ON
up=OFF

Now if i turn on light from a physical button, the state of the switch in BasicUI change from OFF to ON…