UPDATED 2023-10-07
I have reorganized and cleaned up the code for the RESTful API calls to the Studer cloud along with the various Studer sensors. Previously I had everything in the configuration.yaml file, and now only the RESTful API calls are there. The RESTful user name and password have been moved to the secrets.yaml file, and the Studer sensor files have been moved to a studer.yaml file. Also the scan interval is set to a very large number and the actual scans are initiated by an automation to control which API requests are made at any moment to avoid overwhelming the portal.
RESTful Studer API calls:
I have five Studer API calls. The first one requests several Studer performance data points in one call. The others request a single Studer data points. The single data point ones are based on one that can be found here: Read Studer parameters via Xcom-LAN and Rest Sensor
This is the new configuration.yaml file:
#CONFIGURATION.YAML yaml file
# Loads default set of integrations. Do not remove.
default_config:
# Line to enable HA Configuration Editor
config_editor:
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
http:
use_x_forwarded_for: true
trusted_proxies: 127.0.0.1
binary_sensor:
# RESTful INTEGRATIONS
rest:
# Studer API calls are made using RESTful integration blocks of code
# The RESTful integration blocks of code are called by a service in an automation
# The autoation is triggered by a timer and increments a counter that is used to select which RESTful integration block is called.
# The Synoptic data block is called when the counter is (>0 AND <5) OR (>5 AND <10) OR (>10 AND <15) OR (>15 AND <20)
# The AUX 1 data block is called when the counter is <1
# The Battery Temperature data block is called when the counter is >4 AND <6
# The AC Input Voltage data block is called when the counter is >9 AND <11
# The Battery Voltage data block is called when the counter is >14 AND <16
# In each block, replace NNNN with your four digit System ID nummber
# In each block, replace !secret UHASH with your own Studer portal email address hashed in SHA256 either hardcoded in this yaml file or in your secrets.yaml file
# In each block, replace !secret PHASH with your own Studer portal password hashed in MD5 either hardcoded in this yaml file or in your secrets.yaml file
# Studer Synoptic Data Request
- authentication: basic
method: GET
scan_interval: 99999
timeout: 120
resource: "https://api.studer-innotec.com/api/v1/installation/synoptic/NNNN"
headers:
Accept: application/json
UHASH: !secret UHASH
PHASH: !secret PHASH
sensor:
- name: "Studer Synoptic"
unique_id: "studer_synoptic"
value_template: "42"
json_attributes:
- "energy"
- "battery"
- "power"
# Studer Aux contact data request
- authentication: basic
method: GET
scan_interval: 99999
timeout: 120
resource: "https://api.studer-innotec.com/api/v1/installation/user-info/NNNN?device=XT_Group&infoId=3031"
headers:
Accept: application/json
UHASH: !secret UHASH
PHASH: !secret PHASH
sensor:
- name: "Studer Xtender AUX1"
unique_id: "studer_xtender_aux1"
value_template: "44"
json_attributes:
- "status"
- "uIntValue"
- "floatValue"
# Studer Electronic Temperature data request
- authentication: basic
method: GET
scan_interval: 99999
timeout: 120
resource: "https://api.studer-innotec.com/api/v1/installation/user-info/NNNN?device=XT_Group&infoId=3106"
headers:
Accept: application/json
UHASH: !secret UHASH
PHASH: !secret PHASH
sensor:
- name: "Studer Xtender Electronic Temperature"
unique_id: "studer_xtender_electronic_temperature"
value_template: "46"
json_attributes:
- "status"
- "uIntValue"
- "floatValue"
# Studer AC Input Voltage data request
- authentication: basic
method: GET
scan_interval: 99999
timeout: 120
resource: "https://api.studer-innotec.com/api/v1/installation/user-info/NNNN?device=XT_Group&infoId=3011"
headers:
Accept: application/json
UHASH: !secret UHASH
PHASH: !secret PHASH
sensor:
- name: "Studer Xtender AC Input Voltage"
unique_id: "studer_xtender_ac_input_voltage"
value_template: "48"
json_attributes:
- "status"
- "uIntValue"
- "floatValue"
# Studer Battery Voltage data request
- authentication: basic
method: GET
scan_interval: 99999
timeout: 120
resource: "https://api.studer-innotec.com/api/v1/installation/user-info/NNNN?device=XT_Group&infoId=3000"
headers:
Accept: application/json
UHASH: !secret UHASH
PHASH: !secret PHASH
sensor:
- name: "Studer Xtender Battery Voltage"
unique_id: "studer_xtender_battery_voltage"
value_template: "50"
json_attributes:
- "status"
- "uIntValue"
- "floatValue"
# TEMPLATE INTEGRATION
template:
#sensor to identify if daylight savings for selecting summer or winter tariff structure
- binary_sensor:
- name: "Is DST"
state: "{{ now().timetuple().tm_isdst == true }}"
#INCLUDE for tariffs sensor calculations
- sensor: !include tariffs.yaml
#INCLUDE for Studer sensors that copy data from RESTful API call attributes
- sensor: !include studer.yaml
#INCLUDE for Shelly sensor calculations
- sensor: !include shelly.yaml
#INCLUDE for Tuya sensor yaml blocks
- sensor: !include tuya.yaml
Next there is a secrets.yaml file which holds the credentials:
# SECRETS.YAML yaml secrets file
# Use this file to store secrets like usernames and passwords.
# Learn more at https://www.home-assistant.io/docs/configuration/secrets/
#Studer Portal and API credentials
# Where "PHASH" is the password hashed in MD5
# Where "UHASH" is the email address hashed in SHA256
# Where "userLevelCode" is the code required by the API for Installer QSP level access
UHASH: #place your SHA256 encoded username here. It should be a hex code that looks like: 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
PHASH: #place your MD5 encoded password here. It should be a hex code that looks like: 79054025255fb1a26e4bc422aef54eb4
Before moving on to the next step which adds the individual Studer sensors, inspect the attributes that are created by the two RESTful calls. They should look like this:
![Single point api attributes when Studer portal is responding|472x361]
If you aren’t seeing the attribute list it could be something wrong with the way you have entered your credentials, or that the Studer portal is currently having problems.
You can confirm your credentials for the Synoptic data API call here: Studer Web API
Also be aware that the status can show as “unknown” when the Studer portal is not responding. The portal frequently has problems, so if you see “unknown”, check if the portal is having problems by checking the portal’s dashboard in a web browser or using the Studer Android app. If either of those isn’t able to display the data, the RESTful API calls will also have problems. On startup, several of the sensor values can be displayed as “unknown” until new values come in. This can also happen if there isn’t any activity on the sensors due to no solar production, or battery charging or discharging.