Error during setup of component rest → Resource not set for RestData

Since update to 2022.11 I receive the following error during setup of component rest:

Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-03 10:36:02.024 ERROR (MainThread) [homeassistant.setup] Error during setup of component rest
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 235, in _async_setup_component
result = await task
File "/usr/src/homeassistant/homeassistant/components/rest/__init__.py", line 77, in async_setup
return await _async_process_config(hass, config)
File "/usr/src/homeassistant/homeassistant/components/rest/__init__.py", line 97, in _async_process_config
rest = create_rest_data_from_config(hass, conf)
File "/usr/src/homeassistant/homeassistant/components/rest/__init__.py", line 185, in create_rest_data_from_config
raise HomeAssistantError("Resource not set for RestData")
homeassistant.exceptions.HomeAssistantError: Resource not set for RestData
  - platform: rest
    name: knmi_meteoserver
    resource: https://data.meteoserver.nl/api/liveweer.php?locatie=xxxxxx&key=xxxxxxxx
    value_template: "{{value_json['liveweer'][0]['plaats'] | default('api not reachable')}}"
    json_attributes:
      - liveweer
      - no_license
    scan_interval: 6300 

→ Resource not set for RestData

What exactly does it mean, but more important, how can this be solved?

EDIT: After several restarts sensors are OK now.

Hi,
I have the same issue.
Are you sure you didn’t change anything between restarts?
I don’t know how to solve this, right now I did several restarts but that didn’t help.

Thanks

I managed to solve this by changing my configuration: I had the rest sensor under “sensors” now is under “rest” and everything works.

1 Like

This worked for me as well, thanks for providing a fix.

I have other problem after moving the rest sensor in the Rest section, so I rollback to the previous configuration and opened an issue in GitHub, since this was working fine and not it isn’t. Looks like a regression to me.

Issue can be found here: Sensor.Rest not able to start after 2022.11.1 · Issue #81551 · home-assistant/core (github.com)

1 Like

Hi,

This is the second time that I tried to update to 2022.11.2 but get the Rest Sensor errors. I previously rolled back to 2022.11.1 so that my HA instance could continue to operate. I read through this post and the linked Issue #81551 and thought maybe the issue had been addressed by the core changes. But today I tried to update again and faced with the same problems that the Rest Sensor can not be set up on boot.
It is clearly an issue with my REST templates configuration, but I dont clearly understand what I need to do. I checked the Rest documentation but its still not clear to me. I have several Rest sensors throughout my configuration that probably need updating.

Could anyone point me in the right direction with an example of the acceptable configuration?

2022-11-12 12:22:32.904 ERROR (MainThread) [homeassistant.config] Package sensor_rest_gas_price_kw setup failed. Integration rest has duplicate key 'resource_template' (See /config/packages/systems/octopus_agile/sensor_rest_gas_price_kw.yaml:0).
2022-11-12 12:22:32.906 ERROR (MainThread) [homeassistant.config] Package sensor_rest_gas_price_m3 setup failed. Integration rest has duplicate key 'resource_template' (See /config/packages/systems/octopus_agile/sensor_rest_gas_price_m3.yaml:0).
2022-11-12 12:22:32.908 ERROR (MainThread) [homeassistant.config] Package sensor_rest_import_price setup failed. Integration rest has duplicate key 'resource_template' (See /config/packages/systems/octopus_agile/sensor_rest_import_price.yaml:0).
2022-11-12 12:22:32.909 ERROR (MainThread) [homeassistant.config] Package sensor_rest_import_price_pounds setup failed. Integration rest has duplicate key 'resource_template' (See /config/packages/systems/octopus_agile/sensor_rest_import_price_pounds.yaml:0).
2022-11-12 12:22:41.161 ERROR (MainThread) [homeassistant.config] Package solarman_sensors setup failed. Integration rest has duplicate key 'scan_interval' (See /config/packages/systems/sofar_battery_inverter/solarman_sensors.yaml:0).
2022-11-12 12:22:42.096 ERROR (MainThread) [homeassistant.config] Package sensor_rest_myenergi setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/myenergi/general_files/sensor_rest_myenergi.yaml:6).
2022-11-12 12:22:42.098 ERROR (MainThread) [homeassistant.config] Package sensor_rest_myenergi_cmt setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/myenergi/general_files/sensor_rest_myenergi_cmt.yaml:6).

2022-11-12 12:22:55.940 ERROR (MainThread) [homeassistant.config] Invalid config for [rest]: two or more values in the same group of exclusion 'resource' @ data['rest'][0][<resource>]. Got None. (See ?, line ?). Please check the docs at https://www.home-assistant.io/integrations/rest
2022-11-12 12:22:55.946 ERROR (MainThread) [homeassistant.setup] Setup failed for rest: Invalid config.
2022-11-12 12:22:56.675 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-12 12:22:56.679 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-12 12:22:56.682 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-12 12:22:56.684 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-12 12:22:56.687 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.
2022-11-12 12:22:56.689 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform rest.sensor: Unable to set up component.

Some of my config currently looks like this:

rest:
  resource_template: "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-A/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}"
  scan_interval: 1800    
  sensor:
    - name: "Export Price" 
      value_template: "{% if is_state('input_boolean.go_tariff','on') %}4.1{% else %}{{ value_json.results[0].value_inc_vat|round(2) }}{% endif %}"    
      unit_of_measurement: "p/kWh"

    - name: "Export Price Pounds"
      value_template: "{% if is_state('input_boolean.go_tariff','on') %}0.041{% else %}{{ value_json.results[0].value_inc_vat / 100 }}{% endif %}"    
      unit_of_measurement: "£/kWh"
rest:
  resource_template: "https://octopus.energy/api/v1/tracker/G-1R-SILVER-2017-1-A/monthly/future/12/5320/"
  sensor:
    - name: "Gas Price Pounds kWh"
      value_template: "{{ value_json.periods[0].unit_rate / 100 }}"
      unit_of_measurement: "£/kWh"
rest:
  resource_template: "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-A/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}"
  scan_interval: 1800    
  sensor:
    - name: "Import Price"
      value_template: "{% if is_state('binary_sensor.power_hour','on') %}0.0{% elif is_state('input_boolean.go_tariff','on') %}{{ 7.5 if is_state('binary_sensor.go_cheap','on') else 40.13}}{% else %}{{ value_json.results[0].value_inc_vat|round(2) }}{% endif %}"
      unit_of_measurement: "p/kWh"
      

Your configuration is wrong, please have another look at the docs.

You should avoid using multiple top-level keys if you can:

Some integrations support multiple top-level !includes, this includes integrations defining an IoT domain, e.g. light, switch, sensor as well as the automation, script and template integrations, if you give a different label to each one. Configuration for other integrations can instead be split up by using packages. To learn more about packages, see the Packages page.

source

This might work for the rest platform, but if you have them in one place, referencing rest: multiple times isn’t neccessary.
Have a look at the first code block in the docs. You’re missing the - in front of every rest sensor. So your first example should be:

rest:
  - resource_template: "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-A/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}"
    scan_interval: 1800    
    sensor:
      - name: "Export Price" 
        value_template: "{% if is_state('input_boolean.go_tariff','on') %}4.1{% else %}{{ value_json.results[0].value_inc_vat|round(2) }}{% endif %}"    
        unit_of_measurement: "p/kWh"

      - name: "Export Price Pounds"
        value_template: "{% if is_state('input_boolean.go_tariff','on') %}0.041{% else %}{{ value_json.results[0].value_inc_vat / 100 }}{% endif %}"    
        unit_of_measurement: "£/kWh"

Then just put the other rest stuff under the same rest: key, don’t add another one. E.g.:

rest:
  - resource_template: "https://api.octopus.energy/v1/products/AGILE-OUTGOING-19-05-13/electricity-tariffs/E-1R-AGILE-OUTGOING-19-05-13-A/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}"
    scan_interval: 1800    
    sensor:
      - name: "Export Price" 
        value_template: "{% if is_state('input_boolean.go_tariff','on') %}4.1{% else %}{{ value_json.results[0].value_inc_vat|round(2) }}{% endif %}"    
        unit_of_measurement: "p/kWh"

      - name: "Export Price Pounds"
        value_template: "{% if is_state('input_boolean.go_tariff','on') %}0.041{% else %}{{ value_json.results[0].value_inc_vat / 100 }}{% endif %}"    
        unit_of_measurement: "£/kWh"

  - resource_template: "https://octopus.energy/api/v1/tracker/G-1R-SILVER-2017-1-A/monthly/future/12/5320/"
    sensor:
      - name: "Gas Price Pounds kWh"
        value_template: "{{ value_json.periods[0].unit_rate / 100 }}"
        unit_of_measurement: "£/kWh"

  - resource_template: "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-A/standard-unit-rates/?period_from={{ now().year }}-{{ now().month }}-{{ now().day }}T{{ now().hour }}:{% if now().minute <30 %}00{% else %}30{% endif %}&period_to={{ now().year }}-{{ now().month }}-{% if (now().hour == 23) and (now().minute >=30) %}{{ now().day+1 }}{% else %}{{ now().day }}{% endif %}T{% if (now().hour == 23) and (now().minute >=30) %}00{% elif now().minute >=30 %}{{ now().hour+1}}{% else %}{{ now().hour}}{% endif %}:{% if now().minute >=30 %}00{% else %}30{% endif %}"
    scan_interval: 1800    
    sensor:
      - name: "Import Price"
        value_template: "{% if is_state('binary_sensor.power_hour','on') %}0.0{% elif is_state('input_boolean.go_tariff','on') %}{{ 7.5 if is_state('binary_sensor.go_cheap','on') else 40.13}}{% else %}{{ value_json.results[0].value_inc_vat|round(2) }}{% endif %}"
        unit_of_measurement: "p/kWh"
1 Like

Thank you for the guidance and assistance. I made the changes to the REST sensors nd then made a back up and attempted the update to 2022.11.2 After the update there is this warning:

2022-11-13 15:30:48.108 ERROR (MainThread) [homeassistant.config] Package sensor_rest_export_price setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/octopus_agile/sensor_rest_export_price.yaml:0).
2022-11-13 15:30:48.111 ERROR (MainThread) [homeassistant.config] Package sensor_rest_gas_price_kw setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/octopus_agile/sensor_rest_gas_price_kw.yaml:0).
2022-11-13 15:30:48.113 ERROR (MainThread) [homeassistant.config] Package sensor_rest_gas_price_m3 setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/octopus_agile/sensor_rest_gas_price_m3.yaml:0).
2022-11-13 15:30:48.115 ERROR (MainThread) [homeassistant.config] Package sensor_rest_import_price setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/octopus_agile/sensor_rest_import_price.yaml:0).
2022-11-13 15:30:48.116 ERROR (MainThread) [homeassistant.config] Package sensor_rest_import_price_pounds setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/octopus_agile/sensor_rest_import_price_pounds.yaml:0).
2022-11-13 15:30:56.022 ERROR (MainThread) [homeassistant.config] Package solarman_sensors setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/sofar_battery_inverter/solarman_sensors.yaml:0).
2022-11-13 15:30:57.022 ERROR (MainThread) [homeassistant.config] Package sensor_rest_myenergi setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/myenergi/general_files/sensor_rest_myenergi.yaml:6).
2022-11-13 15:30:57.024 ERROR (MainThread) [homeassistant.config] Package sensor_rest_myenergi_cmt setup failed. Integration rest cannot be merged. Expected a dict. (See /config/packages/systems/myenergi/general_files/sensor_rest_myenergi_cmt.yaml:6).

Any idea what it means about being merged? currently my HA setup is compartmentalized in to /config/packages/systems with separate folders for items to give clarity, something like this:


I did read that the system tries to put all the REST items in to a single file…is that what its trying to do here?