#RESTful sensor issue

1 messages · Page 1 of 1 (latest)

grave hawk
#

Hey, I'm having trouble with my restful sensor. It should track a state of a light which is connected to the Quido ETH from xml file. The problem is, that the sensor is returning the value with ' character like " 0 ' ". I want it to be a single integer. Anyone can help?

#

Sensor template:

- platform: rest
  name: Smart svetlo
  scan_interval: 1
  resource: http://192.168.X.X/fresh.xml
  value_template: >
    {% for x in value_json["root"]["dout"] %}
    {% if x["@id"] == "2" %}
    {{x["@val"] | int}}
    {% endif %}
    {% endfor %}'
#

xml file:

<root xmlns="http://www.papouch.com/xml/quido/act">
  <dout id="1" name="Hlavne svetlo" sts="0" val="0" pic="1" mde="1" pars="1;0;1250;-550;2"/>
  <dout id="2" name="Smart svetlo 1" sts="0" val="0" pic="13" mde="0" pars="1;0;1250;-550;1"/>
  <dout id="3" name="HA RaspberryPi" sts="0" val="0" pic="13" mde="0" pars="1;0;1250;-550;1"/>
</root>
lime solar
#

remove the single quoate at the end of your rest

grave hawk
#

I can't believe I didn't notice that.... Thanks it works now, thanks.

#

I have another question regarding this xml. I want to create a switch that can turn on/off the light. I saw a few switches in community forum, but all of them were json files. How should the switch look like in this case?

lime solar
#

Do you know how to do this from a command line? I have no clue how this/your switch works

grave hawk
#

Actually, I was trying to do it with curl command, but that didn't work.

lime solar
#

so what does the manufacturer write on it? I have seen a few switches via MQTT so one can send json via rest to do things

#

I have no clue what your switch accepts

#

what is the brand?

#

isn't there a 'normal' intergation with HA?

grave hawk
#

Ok, so if anyone encounters the same problem, this is how I proceeded:
I created rest commands:

rest_command:
  zapni_lampu:
    url: 'http://192.168.X.X/set.xml?type=s&id=2'
    method: GET

  vypni_lampu:
    url: 'http://192.168.X.X/set.xml?type=r&id=2'
    method: GET 
#

And then I created a light entity:

- platform: template
  lights:
    smart_svetlo:
      friendly_name: Smart svetlo
      value_template: "{{ states('sensor.smart_svetlo') == '1' }}"
      turn_on:
        service: rest_command.zapni_lampu
      turn_off:
        service: rest_command.vypni_lampu