Error "Platform rest does not generate unique IDs" when using a RESTful sensor

Hi all

I use RESTful sensors to get information about the water used RESTful
The code for one sensor looks like this:

rest:
- resource: !secret saures_link_meters
    scan_interval: 14460
    headers:
      User-Agent: HTTPie/3.2.2
    params:
      sid: "{{ states('sensor.saures_api_sid') }}"
      id: "{{ states('sensor.saures_storage_id_object' ) }}"
    sensor:
#GET select. Controller
      - name: "Saures API: Controller"
        unique_id: saures_api_controller
        icon: mdi:waterfall
        value_template: "{{ value_json.status }}"
        json_attributes_path: "$.data.sensors.0"
        json_attributes:
          - active
          - bat
          - cap_state
          - check_hours
          - check_period_display
          - empty_inputs
          - firmware
          - hardware
          - last_connection
          - last_connection_warning
          - lic_channels
          - local_ip
          - log
          - model
          - name
          - nbiot
          - power_supply
          - readout_dt
          - request_dt
          - requests
          - rssi
          - scan
          - send
          - sn
          - ssid
          - vol

The code works fine, gets the value, creates the sensor, but only once.
Then the error occurs:

  • Platform rest does not generate unique IDs. ID saures_api_controller already exists - ignoring sensor.saures_api_controller

Searching for this error showed that the issue was opened a year ago, but there is still no solution. #90394. Or I was looking badly ))

What solution can be found for the operation of the sensors?

PS: I tried changing the unique_id to something similar to 00adcc44-e097-43b7-b547-f3f7ff60c862. The result is the same.

What happens if you remove the unique_id? Do you need it there for customisation or entity ID renaming?

If you remove the unique_id, a new sensor is created each time it is called.

Preusmably sensor.saures_api_controller_2 and so on?

Yes that’s right.

RESTful Sensor - Home Assistant.

Explain what information I should get from your answer?

That’s the schema for a restful sensor, and it includes a unique_id key you can use.
That is a direct link to it.

I would be grateful if you could decipher your message, I don’t understand.
should I use this code?

$ curl -X GET http://192.168.1.31/temperature/
{"temperature": 77, "id": "sensor02", "name": "livingroom", "connected": true}

if this is the correct answer, can you show me how to create a similar sensor with parameters

Friends, is this really an unsolvable problem?

Can you try hard-coding the URL rather than using a secret?

Of course I did. It does not change anything.

Here’s what the full code looks like

This sensor works fine and receives information regularly every 4 hours.

#RESTful Sensor. Documentation https://www.home-assistant.io/integrations/sensor.rest
#Getting SID. Upon authorization, the system issues a sid, all subsequent requests are carried out by passing this identifier. Lifetime of #identifier 15 minutes
sensor:
  - platform: rest
    name: "Saures API: SID"
    unique_id: saures_api_sid
    icon: mdi:package-down
    resource: https://api.saures.ru/1.0/login
    method: POST
    scan_interval: 14400
    headers:
      Content-Type: application/x-www-form-urlencoded; charset=utf-8
      User-Agent: HTTPie/3.2.2
    payload: !secret saures_login_payload
    value_template: "{{ value_json.data.sid }}"

These sensors fire once when created and then cause an error.

#Make a request to objects to retrieve the object ID. This is necessary in order to make requests where sid and id are required
rest:
#GET select user/objects
  - resource: https://api.saures.ru/1.0/user/objects
    scan_interval: 14460
    method: GET
    headers:
      User-Agent: HTTPie/3.2.2
    params:
      sid: "{{ states('sensor.saures_api_sid') }}"
    sensor:
#GET select object
      - name: "Saures API: Object"
        unique_id: saures_api_object
        icon: mdi:home
        value_template: "{{ states('sensor.saures_storage_id_object' ) }}"
        json_attributes_path: "$.data.objects.0"
        json_attributes:
          - access_level
          - connect_dt
          - enable
          - house
          - id
          - label
          - number
          - object_company_account
          - object_company_inn
          - object_company_name
          - object_company_url
          - personal_account
          - tariffs

#GET запрос object/meters
  - resource: https://api.saures.ru/1.0/object/meters
    scan_interval: 14520
    headers:
      User-Agent: HTTPie/3.2.2
    params:
      sid: "{{ states('sensor.saures_api_sid') }}"
      id: "{{ states('sensor.saures_storage_id_object' ) }}"
    sensor:
#GET select. Controller
      - name: "Saures API: Controller"
        unique_id: saures_api_controller
        icon: mdi:waterfall
        value_template: "{{ value_json.status }}"
        json_attributes_path: "$.data.sensors.0"
        json_attributes:
          - active
          - bat
          - cap_state
          - check_hours
          - check_period_display
          - empty_inputs
          - firmware
          - hardware
          - last_connection
          - last_connection_warning
          - lic_channels
          - local_ip
          - log
          - model
          - name
          - nbiot
          - power_supply
          - readout_dt
          - request_dt
          - requests
          - rssi
          - scan
          - send
          - sn
          - ssid
          - vol

#GET request. Water meter 1
      - name: "Saures API: Water Meter 1"
        unique_id: saures_api_water_meters_1
        icon: mdi:counter
        value_template: "{{ value_json.data.sensors.0.meters.0.vals.0 }}"
        unit_of_measurement: m³
        state_class: total
        device_class: water
        json_attributes_path: "$.data.sensors.0.meters.0"
        json_attributes:
          - approve_dt
          - eirc_num
          - input
          - meter_id
          - meter_name
          - sn
          - state
          - type
          - unit
          - vals

#GET request. Water meter 1
      - name: "Saures API: Water Meter 2"
        unique_id: saures_api_water_meters_2
        icon: mdi:counter
        value_template: "{{ value_json.data.sensors.0.meters.1.vals.0 }}"
        unit_of_measurement: m³
        state_class: total
        device_class: water
        json_attributes_path: "$.data.sensors.0.meters.1"
        json_attributes:
          - approve_dt
          - eirc_num
          - input
          - meter_id
          - meter_name
          - sn
          - state
          - type
          - unit
          - vals

#Templates. Documentation https://www.home-assistant.io/integrations/template/
#Save the object ID so that after a reboot Home Assistant Saures does not reset the sensor
template:
  - trigger:
      - platform: template
        value_template: "{{ state_attr('sensor.saures_api_object', 'id') | is_defined }}"
    sensor:
      - name: "Saures Storage: ID Object"
        unique_id: saures_storage_id_objectg
        icon: mdi:water-well
        state: "{{ state_attr('sensor.saures_api_object','id') }}"

Platform rest does not generate unique IDs. saures_api_object already exists - ignoring sensor.saures_api_controller
Platform rest does not generate unique IDs. ID saures_api_controller already exists - ignoring sensor.saures_api_controller
Platform rest does not generate unique IDs. saures_api_water_meters_1 already exists - ignoring sensor.saures_api_controller
Platform rest does not generate unique IDs. saures_api_water_meters_2 already exists - ignoring sensor.saures_api_controller

Since the guru is silent, it means no one could find a solution.

I am looking for helo on this particular topic.
I also have the issue with the “already exist unique_id”

I fixed the situation using the following solution suggested by a user @timr49

Two weeks no problem.