Input_text is not initialised before RESTful integration is executed

Hi All

I have a RESTful integration configured where the URL has parameter values that use the current date - hence I need to use resource_template.
The URL path also contains a value that I’d prefer to keep secret and so would like to store it in my secrets file. I’m using an input_text to provide the bridge between the secrets file and my template (as described here and many other places in this forum)

Here is the content of my package:

solar_analytics:
  input_text:
    sa_site_id:
      initial: !secret sa_site_id
      mode: password
  rest:
    - authentication: basic
      username: !secret sa_username
      password: !secret sa_password
      scan_interval: 60
      resource_template: "https://portal.solaranalytics.com.au/api/v2/site_data/{{ states('input_text.sa_site_id') }}?raw=true&tstart={{ now().strftime('%Y%m%d') }}&tend={{ (now() + timedelta(days=1)).strftime('%Y%m%d') }}&trunc=false"

      sensor:
        - name: "sa_site_data_raw_grid"
          value_template: "OK"
          json_attributes_path: "$.data[0]"
          json_attributes: "data"
        - name: "sa_site_data_raw_solar"
          value_template: OK"
          json_attributes_path: "$.data[1]"
          json_attributes: "data"

The problem I’m having is that, after I restart HA I always get some of these warnings (which I consider to be errors) in the log:
WARNING (MainThread) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON

I’ve turned debugging on for the rest component and can see that the problem is that the state of the input_text is “unknown” when the REST sensor is first executed:
DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://portal.solaranalytics.com.au/api/v2/site_data/unknown?raw=true&tstart=20220316&tend=20220317&trunc=false

The problem only seems to occur for the very first execution of the REST sensor after a restart so it’s not a “huge” problem but it definitely messes up the history of other template sensors that are based on these REST sensors (I get zero values in the history whenever I reboot HA).

Is there any way I can get the REST sensor to wait until the input_text is initialised?
If possible, I’d prefer to do this using standard configuration options rather than mess around with automations etc…

Much appreciated

1 Like

Glen,
I am having a similar issue. Just wondering if you found a solution?
-Tim.