Hi all,
Here’s a challenge which I’m hoping you can help me with. I’ll outline what I’m trying to do first, then describe a couple of the specific parts I’m struggling with for starters.
The challenge:
I’m looking at using Predbat for automating our home battery, however, our electricity demand is dominated by our heat pump, and strongly linked to the outside temperature. From the last few months’ historical data I can get a straightforward quadratic curve fit formula which I can use to convert from forecast temperature to a predicted heat demand. This can then be fed as an input to Predbat as described here. I think the steps are, broadly:
- Extract forecast temperatures from a weather forecast entity, say hourly values for the next 24 hours as per the Forecast Home entity;
- Use my formula to convert to a set of heat demand values (maybe some other mathematical tweaks to add in future, but let’s start with the basics);
- Arrange the new values in the prescribed format (Predbat wants this in the form of a sensor with two attributes: timestamps and incrementing heat demand).
So, some questions to start with:
Q1. Choosing the right HA tools - in other languages/platforms, I feel like I could code this in half an hour, but I’m really struggling here with the distinctions and capability differences between sensors, scripts, services, automations, etc. I haven’t found a clear map of this in the documentation anywhere - if I’ve missed something obvious, please point me to it. My current thinking is that this should be achievable in a template sensor - does this seem like the right approach? Or can I use a script to get data from a sensor/service and feed it into a new sensor?
Q2. Getting the forecast data - for step 1 above, it looks like the example here ought to be spot on. (I would then in edit the sensor attributes section at the bottom to perform my calculations and produce an output in the correct format, but let’s get the basics working first.) A few tweaks seem necessary (e.g. entity_id: weather.forecast_home not weather.home), as per this thread. But I can’t seem to get this to work at all - it just results in “Unavailable”.
To be specific, I am pasting the following into a new template sensor:
template:
- trigger:
- platform: time_pattern
hours: /1
action:
- service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.forecast_home
response_variable: hourly_forecast_data
sensor:
- name: Weather Forecast Hourly
unique_id: weather_forecast_hourly
state: "{{ now().isoformat() }}"
attributes:
forecast: "{{ hourly_forecast_data['weather.forecast_home'].forecast }}"
None of the available options in the ‘Unit of measurement’, ‘Device class’ or ‘State class’ menus seem appropriate, so I have left these blank - if these should be set to something specific, please advise.
I can see that the service call seems to work - pasting the following into Developer Tools > Services gets a sensible output:
service: weather.get_forecasts
data:
type: hourly
target:
entity_id: weather.forecast_home
But it doesn’t seem to be doing anything when put into the template sensor.
System info as follows, running on a RPi5/8GB:
Any pointers or suggestions much appreciated (along with requests for any crucial info you need to know which I’ve missed!).
Cheers,
Jo