Trying to use platform rest sensor(s)s to pull values for a solar inverter only between sunrise and sunset.
I thought this should be a fairly common thing to do, but I have not found it in my searching.
My local webserver only polls the inverter communications C++ linux executable during sunrise to sunset, so there is no point HA polling outside those times.
Most values go to zero after sunset, and the inverter shuts off also when there is no sun on the panels to power it.
I get values for my older solar inverter from my local webserver from a json php ( https://xxx.xxx.xxx.xxx/x/x/programlive.php?invtnum=1 )
It returns values (e.g. some of them listed below) during daylight:
{"SDTE":<RETRACTED>,"I1V":281.9,"I1A":5.3,"I1P":1495,"I2V":308.2,"I2A":5.4,"I2P":1658,"I3V":0,"I3A":0,"I3P":0,"I4V":0,"I4A":0,"I4P":0,"G1V":243.6,"G1A":12.2,"G1P":2953,"G2V":0,<LOTS MORE RETRACTED>,"KWHT":50990.507,"timestamp":"26\/01\/2023 15:56:21",<RETRACTED>}
At night:
{"SDTE":<RETRACTED>,"I1V":0,"I1A":0,"I1P":0,"I2V":0,"I2A":0,"I2P":0,"I3V":0,"I3A":0,"I3P":0,"I4V":0,"I4A":0,"I4P":0,"G1V":0,"G1A":0,"G1P":0,"G2V":0,"G2A":0,"G2P":0,"G3V":0,"G3A":0,"G3P":0,"FRQ":0,"EFF":0,"INVT":0,"BOOT":0,"SSR":0,"PMAXOTD":0,"PMAXOTDTIME":0,"timestamp":"25\/01\/2023 23:40:25","riso":0,"ileak":0,"awdate":"--:--"}
All values go to 0 after sunset except timestamp and KWHT
KWHT is the inverter total kWh produced (forever increasing so never shows zero) and does not show in the json at all after sunset (which is what I use in the HA energy dashboard).
HA OS 9.4 / Core 2023.1.7 with all latest updates installed.
config.yaml:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# My Modifications
# Groups
group: !include groups.yaml
# Sensors
sensor: !include sensors.yaml
# Templates
template: !include templates.yaml
I currently have the sensors setup in:
sensors.yaml
#sensor:
# Solar Monitoring (West)
- platform: rest
name: West Solar kWh Total
resource: !secret solar_west_res
device_class: energy
state_class: total_increasing
unit_of_measurement: kWh
value_template: "{{ value_json.KWHT }}"
- platform: rest
name: West Solar Power
resource: !secret solar_west_res
device_class: power
unit_of_measurement: W
value_template: "{{ value_json.G1P }}"
force_update: true
- platform: rest
name: West Solar Amp
resource: !secret solar_west_res
unit_of_measurement: A
value_template: "{{ value_json.G1A }}"
- platform: rest
name: West Solar Max Output
resource: !secret solar_west_res
unit_of_measurement: W
value_template: "{{ value_json.PMAXOTD }}"
- platform: rest
name: West Solar Max Output Time
resource: !secret solar_west_res
value_template: "{{ value_json.PMAXOTDTIME }}"
# The remaining sensors are usually below here but cut to keep it short and readable
I should probably convert these to the modern style, as all my other templates and sensors are.
And also make them all a single call to be more efficient as well!