REST Platform executes twice?

I have a rest sensor configured for the psa-car-controller running on a separate machine. Below that I configured sensors from the json values.

- platform: rest
  name: c5_aircross
  scan_interval: 60
  timeout: 30
  value_template: "OK"
    - energy
    - timed_odometer
    - battery
    - preconditionning
    - environment
    - ignition
    - last_position
- platform: template
      friendly_name: "C5 last lat"
      unique_id: "c5_last_lat"
      value_template: '{{ states.sensor.c5_aircross.attributes["last_position"]["geometry"]["coordinates"][1]}}'
      icon_template: mdi:map-marker-multiple
      friendly_name: "C5 last long"
      unique_id: "c5_last_long"
      value_template: '{{ states.sensor.c5_aircross.attributes["last_position"]["geometry"]["coordinates"][0]}}'
      icon_template: mdi:map-marker-multiple
      friendly_name: "C5 last height"
      unique_id: "c5_last_height"
      value_template: '{{ states.sensor.c5_aircross.attributes["last_position"]["geometry"]["coordinates"][2]}}'
      icon_template: mdi:map-marker-multiple
      friendly_name: "C5 Koordinaten"
      unique_id: "c5_coordinates"
      value_template: "{{ states('sensor.c5_ignition_type') }}"
        latitude: "{{states('sensor.c5_last_position_lat')|float(7)}}"
        longitude: "{{states('sensor.c5_last_position_long')|float(7)}}"'''

It seems that the sensors get executed twice when the REST call gets done.
I get the coordinates and create a sensor that has the coordinates as attributes to show on a map.
Now the problem seem that c5_coordinates gets set twice, the first time with only the lat, the second time also the long. On the Map I can see two entries for the same point in time.


I have marked two pairs that show the same timestamp (same second) but different lat.

Any ideas whats wrong here?

You’re creating a chain of updates. Instead use:

      friendly_name: "C5 Koordinaten"
      unique_id: "c5_coordinates"
      value_template: "{{ states('sensor.c5_ignition_type') }}"
        latitude: "{{ state_attr('sensor.c5_aircross', 'last_position')['geometry']['coordinates'][1] }}"
        longitude: "{{ state_attr('sensor.c5_aircross', 'last_position')['geometry']['coordinates'][0] }}"

Then consider using modern format template sensor definitions:

Or consider using the Rest integration to get all your coordinates and attributes as individual sensors with only one call to the resource and no need for template sensors.

configuration.yaml (not sensors.yaml)

  - resource:
    scan_interval: 60
      - name: "C5 Last Lat"
        value_template: "{{ value_json['last_position']['geometry']['coordinates'][1] }}"
        icon: mdi:map-marker-multiple
      - name: "C5 Last Long"
        value_template: "{{ value_json['last_position']['geometry']['coordinates'][0] }}"
        icon: mdi:map-marker-multiple
      - name: "C5 Energy"
        value_template: "{{ value_json['energy'] }}"
        device_class: energy # assuming this is an energy total?
        unit_of_measurement: Wh # or kWh
      - name: "C5 Timed Odometer"
        value_template: "{{ value_json['timed_odometer'] }}"
        icon: "mdi:counter"
        unit_of_measurement: km # check this is the correct unit. 
        device_class: distance
      - name: "C5 Timed Battery"
        value_template: "{{ value_json['battery'] }}"
        device_class: battery # only use this if the returned value is % SoC
      - name: "C5 Preconditioning" # check how this is actually spelled
        value_template: "{{ value_json['preconditioning'] }}"
      - name: "C5 Environment" 
        value_template: "{{ value_json['environment'] }}"
      - name: "C5 Ignition" 
        value_template: "{{ value_json['ignition'] }}"
1 Like