I have a small py code directly in HA to change a state let me check how restricted this is.
Heh, try to use any of the Python builtins like import
Edit: just to be clear, I’m referring to Python Scripts - Home Assistant
I think you can use it directly see example
if 'entity_id' not in data:
logger.warning("===== entity_id is required if you want to set something.")
else:
data = data.copy()
inputEntity = data.pop('entity_id')
inputStateObject = hass.states.get(inputEntity)
if inputStateObject:
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
else:
inputState = 'unknown'
inputAttributesObject = {}
if 'state' in data:
inputState = data.pop('state')
logger.debug("===== new attrs: {}".format(data))
inputAttributesObject.update(data)
hass.states.set(inputEntity, inputState, inputAttributesObject)
But not sure how to create new sensor
This is just really complicated, I’ll just add support via configuration.yaml
. Multiple PV arrays is rare anyway and most users will know how to manually edit a configuration file
Yes with jinja maybe something like this
{% set watts1 = states.sensor.energy_production_d2.attributes['watts'] %}
{% set watts2 = states.sensor.energy_production_d2_2.attributes['watts'] %}
{% for date in watts1 %}
{{ date }}
{{ watts1[date] + watts2[date] }}
{% endfor %}
EDIT here we go:
sensor:
- name: "energy_production_today_all"
state: >
{{ (states('sensor.energy_production_today') | float(default=0) + states('sensor.energy_production_today_2') | float(default=0)) | round(2) }}
unit_of_measurement: "kWh"
device_class: energy
attributes:
watts: >
{% set watts1 = states.sensor.energy_production_today.attributes['watts'] %}
{% set watts2 = states.sensor.energy_production_today_2.attributes['watts'] %}
{% set wattsNew = states.sensor.energy_production_today_2.attributes['watts'] %}
{% for date in watts1 %}
{% set wattsNew = (watts1[date] + watts2[date]) %}
{% endfor %}
{{ wattsNew }}
not that rare I’d say…
Ok, but how can it be then that the issue occurs everyday in the afternoon and is gone the next day despite the public ip-address being changed every night?
Or in other words - how often am I supposed to change my ip-address just to avoid this error?
no idea I am afraid. That’s the answer I had received at the time. The problem went away for me after 1-2 days.
The log says
Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht
Logger: custom_components.open_meteo_solar_forecast
Quelle: helpers/update_coordinator.py:312
Integration: Open-Meteo Solar Forecast (Dokumentation, Probleme)
Erstmals aufgetreten: 17:08:01 (758 Vorkommnisse)
Zuletzt protokolliert: 20:29:43
Unexpected error fetching open_meteo_solar_forecast data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/open_meteo_solar_forecast/coordinator.py", line 63, in _async_update_data
return await self.forecast.estimate()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/open_meteo_solar_forecast/open_meteo_solar_forecast.py", line 155, in estimate
data = await self._request(
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/open_meteo_solar_forecast/open_meteo_solar_forecast.py", line 122, in _request
raise OpenMeteoSolarForecastRatelimitError("Rate limit exceeded")
open_meteo_solar_forecast.exceptions.OpenMeteoSolarForecastRatelimitError: Rate limit exceeded
I’m not sure if it is interesting, but I self-host Open-Meteo and could probably make the access available to others but I’d rather put it behind Cloudflare or something before I do so. No promises if I follow through on this or not.
This is my template sensor to combine the energy production for two arrays.
- platform: template
sensors:
energy_production_today_sum:
friendly_name: "Energy Production Today Sum"
unit_of_measurement: "kWh"
device_class: energy
value_template: >-
{% set sensor1 = states('sensor.energy_production_today_2') |float %}
{% set sensor2 = states('sensor.energy_production_today_3') |float %}
{% set total_watts = sensor1 + sensor2 %}
{{ total_watts }}
attribute_templates:
watts: >-
{% set sensor1 = state_attr('sensor.energy_production_today_2', 'watts') %}
{% set sensor2 = state_attr('sensor.energy_production_today_3', 'watts') %}
{% set ns = namespace(output=[]) %}
{% for time, value in sensor1.items() %}
{% set sum_value = value + sensor2[time] %}
{% set output_item = {time:sum_value} %}
{% set ns.output = ns.output + [output_item] %}
{% endfor %}
{{ ns.output }}
wh_period: >-
{% set sensor1 = state_attr('sensor.energy_production_today_2', 'wh_period') %}
{% set sensor2 = state_attr('sensor.energy_production_today_3', 'wh_period') %}
{% set ns = namespace(output=[]) %}
{% for time, value in sensor1.items() %}
{% set sum_value = value + sensor2[time] %}
{% set output_item = {time:sum_value} %}
{% set ns.output = ns.output + [output_item] %}
{% endfor %}
{{ ns.output }}
I have 3 arrays on 2 inverters.
But is not the complete the same, correct? The array looks different
I have the same error.
I’m using 3 different config entry’s.
Where do you have this - in configuration.yaml?
But if you request every 30mins it should never get a problem at all:
Less than 10’000 API calls per day, 5’000 per hour and 600 per minute . You may only use the free API services for non-commercial purposes.
But I am, the issue is simply that people are using CGNATed IPv4
Normal sensor
Your sensor
I put the sensor in configuration.yaml but I don’t see it upon a restart. It seems it isn’t created / made available
Not sure I understand? It takes all the data from both sensors and aggregates it