Pass-on secrets to sensor definition?

please let me add this extra post, since it is a separate but closely related to this thread https://community.home-assistant.io/t/solaredge-solar-panels-support/14340:

how can we declare these sensors using the api key and site id from the secrets file.

Currently this is in the sensor-definition :

- platform: rest
  resource: https://monitoringapi.solaredge.com/site/MYSITEID/overview.json?api_key=MYAPIKEY
  value_template: '{{ value_json.overview.lastDayData.energy | float / 1000 | round(1) }}'
  name: 'SolarEdge Last Day'
  unit_of_measurement: 'kWh'
  scan_interval: 900 

Obviously i need the MYSITEID and MYAPIKEY in the secrets file, but i don’t know the correct syntax for that yet.

Thanks,
Marius

1 Like

You pass the whole line as a secret:

- platform: rest
  resource: !secret resource
  value_template: '{{ value_json.overview.lastDayData.energy | float / 1000 | round(1) }}'
  name: 'SolarEdge Last Day'
  unit_of_measurement: 'kWh'
  scan_interval: 900 

and in secrets.yaml…

resource: https://monitoringapi.solaredge.com/site/MYSITEID/overview.json?api_key=MYAPIKEY
2 Likes

…duh…
sometimes,
how simple and straightforward can it be.
Thanks!
and sorry…

1 Like

Ha, nothing to be sorry about, there will be plenty of people who will learn how to do this from you asking the question :slight_smile:

1 Like