Sensor template (update and

Hi,

I created a sensor to catch a temperature.

I have two questions :
Is it possible to use the template directly in the scrape ?
If it’s not possilbe, how can I update the entity when the value change ?

sensor:
  - platform: scrape
    resource: http://192.168.0.3/details.xml
    name: temp_piscine_scrape
    select: "PrimaryValue"

  - platform: template
    sensors:
      temp_piscine:
        entity_id: sensor.temppiscine
        friendly_name: Température piscine
        value_template: "{{ states('sensor.temp_piscine_scrape').split(' ')[0] |round(2) }}"
        device_class: temperature
        unit_of_measurement: "°C"

I hope you can help me :=)

The docs show no ‘value_template’ in the configuration variables, but the examples do. :thinking:
I think it should work with one sensor, just give it a try.

I tried to use a value_template in a scrape platefomr but this don’t work :upside_down_face:

I examined the scrape sensor’s source-code and value_template is supported.

It’s strange because I tried this and I have no value …

  • platform: scrape
    resource: http://192.168.0.3/details.xml
    name: temp_piscine_pac_scrape
    select: “PrimaryValue”
    device_class: temperature
    unit_of_measurement: “°C”
    value_template: “{{ states(‘sensor.temp_piscine_pac_scrape’).split(’ ')[0] |round(2) }}”

Not really. Think about what this template is trying to do:

value_template: "{{ states('sensor.temp_piscine_pac_scrape').split(' ')[0] |round(2) }}"

Its purpose is to set the state of of sensor.temp_piscine_pac_scrape. It attempts to do that by getting its own state which it will split … oh wait … how is it going to get its own state if it has never set it yet?

Try this:

value_template: "{{ value.split(' ')[0] | round(2) }}"

In the future, please format your code. YAML indenting and quotation characters are critical for proper operation and they’re all lost if you don’t format your code.

Sorry for stupid questions :expressionless:

It’s ok now with your code …

Thank you for your help :slight_smile:

Now I wolud like to parse the xml file above. The porblem is that I would like to catch those values “PrimaryValue”
I can catch the first one but I don’t know how to catch the second one …

Do you know how to do this ?

<Devices-Detail-Response xmlns="http://www.embeddeddatasystems.com/schema/owserver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<PollCount>15035426</PollCount>

<DevicesConnected>2</DevicesConnected>

<LoopTime>0.066</LoopTime>

<DevicesConnectedChannel1>0</DevicesConnectedChannel1>

<DevicesConnectedChannel2>0</DevicesConnectedChannel2>

<DevicesConnectedChannel3>2</DevicesConnectedChannel3>

<DataErrorsChannel1>92</DataErrorsChannel1>

<DataErrorsChannel2>0</DataErrorsChannel2>

<DataErrorsChannel3>5510547</DataErrorsChannel3>

<VoltageChannel1>4.27</VoltageChannel1>

<VoltageChannel2>4.41</VoltageChannel2>

<VoltageChannel3>4.16</VoltageChannel3>

<VoltagePower>4.63</VoltagePower>

<DeviceName>OWServer_v2-Enet</DeviceName>

<HostName>EDSOWSERVER2</HostName>

<MACAddress>00:04:A3:59:29:05</MACAddress>

<owd_DS18B20 Description="Programmable resolution thermometer">

<Name>DS18B20</Name>

<Family>28</Family>

<ROMId>D30000027B792928</ROMId>

<Health>1</Health>

<Channel>3</Channel>

<RawData>

DA014B465FFF06104100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

</RawData>

<PrimaryValue>29.6250 Deg C</PrimaryValue>

<Temperature Units="Centigrade">29.6250</Temperature>

<UserByte1 Writable="True">75</UserByte1>

<UserByte2 Writable="True">70</UserByte2>

<Resolution>11</Resolution>

<PowerSource>0</PowerSource>

</owd_DS18B20>

<owd_DS18B20 Description="Programmable resolution thermometer">

<Name>DS18B20</Name>

<Family>28</Family>

<ROMId>140000038B657B28</ROMId>

<Health>1</Health>

<Channel>3</Channel>

<RawData>

E2014B467FFF0E109100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

</RawData>

<PrimaryValue>30.1250 Deg C</PrimaryValue>

<Temperature Units="Centigrade">30.1250</Temperature>

<UserByte1 Writable="True">75</UserByte1>

<UserByte2 Writable="True">70</UserByte2>

<Resolution>12</Resolution>

<PowerSource>0</PowerSource>

</owd_DS18B20>

</Devices-Detail-Response>

I found :=)

I used this code to navigate in the xml file

select: 'PrimaryValue'
    index: 2