@pasarn I use nordpool 24 hour power prices and Emhass PV scraper which gives 24 hour PV forecast using the dayahead-optimization. Emhass gives very good prediction when to switch on the water heater or other deferales when the power price is low or the solar cell gives high energy. When the price is high it prediction to switch off the water heater.
I have also used Tibber price data. I use the home_assistant_tibber_data plugin for getting the price data. The plugin has now some problems to update every day the price data so I wait for a fix from the developer.
Here is my shell commands I use:
shell_command:
trigger_nordpool_forecast: "curl -i -H \"Content-Type: application/json\" -X POST -d '{
\"load_cost_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},
\"prod_price_forecast\":{{((state_attr('sensor.nordpool_uten_avgifter', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool_uten_avgifter', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}},
\"def_total_hours\":{{states('sensor.list_operating_hours_of_each_deferrable_load')}}
}' http://localhost:5000/action/dayahead-optim"
publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"custom_deferrable_forecast_id\": [
{\"entity_id\": \"sensor.p_deferrable0\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmtvannsbereder\"},
{\"entity_id\": \"sensor.p_deferrable1\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmekabel stue og kjøkken\"},
{\"entity_id\": \"sensor.p_deferrable2\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmekabel bad1etg\"},
{\"entity_id\": \"sensor.p_deferrable3\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmekabel bad2etg\"},
{\"entity_id\": \"sensor.p_deferrable4\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmekabel gang\"},
{\"entity_id\": \"sensor.p_deferrable5\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Varmepumpe\"},
{\"entity_id\": \"sensor.p_deferrable6\",\"unit_of_measurement\": \"W\", \"friendly_name\": \"Easee lader\"}
]}' http://localhost:5000/action/publish-data"
And here is the template sensor: sensor.list_operating_hours_of_each_deferrable_load which you can read more about here: example-to-pass-data-at-runtime
template:
- sensor:
- name: "List operating hours of each deferrable load"
unique_id: e4b566c1-6024-4157-8ef5-97c87bcf382c
state: >-
{% if states("sensor.outdoor_temperature_mean_over_last_12_hours") < "10" %}
{{ [6, 3, 3, 3, 3, 3, 6] | list }}
{% elif states("sensor.outdoor_temperature_mean_over_last_12_hours") >= "10" and states("sensor.outdoor_temperature_mean_over_last_12_hours") < "15" %}
{{ [6, 2, 2, 2, 2, 2, 6] | list }}
{% elif states("sensor.outdoor_temperature_mean_over_last_12_hours") >= "15" and states("sensor.outdoor_temperature_mean_over_last_12_hours") < "20" %}
{{ [6, 1, 1, 1, 1, 1, 6] | list }}
{% elif states("sensor.outdoor_temperature_mean_over_last_12_hours") >= "20" and states("sensor.outdoor_temperature_mean_over_last_12_hours") < "25" %}
{{ [6, 0, 0, 0, 0, 0, 6] | list }}
{% else %}
{{ [6, 2, 2, 2, 2, 2, 6] | list }}
{% endif %}
If you want to update the forecast more often you can use the mpc optimization.
Here are the updated shell commands with total number of hours inside the prediction horizon window, in my case 6h:
Waterheater: 2 hours
Floorheating: 3 hours
“def_total_hours”:[2,3,3,3,3,3,3,3]
shell_command:
publish_data: "curl -i -H \"Content-Type: application/json\" -X POST -d '{}' http://localhost:5000/action/publish-data"
trigger_nordpool_forecast: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}}}' http://localhost:5000/action/dayahead-optim"
trigger_nordpool_mpc: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.nordpool', 'raw_today') | map(attribute='value') | list + state_attr('sensor.nordpool', 'raw_tomorrow') | map(attribute='value') | list))[now().hour:][:24]}}, \"prediction_horizon\":6, \"def_total_hours\":[2,3,3,3,3,3,3,3]}' http://localhost:5000/action/naive-mpc-optim"
trigger_entsoe_mpc: "curl -i -H \"Content-Type: application/json\" -X POST -d '{\"load_cost_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24] }},\"prod_price_forecast\":{{((state_attr('sensor.entsoe_average_electricity_price_today', 'prices_today') | map(attribute='price') | list + state_attr('sensor.entsoe_average_electricity_price_today', 'prices_tomorrow') | map(attribute='price') | list))[now().hour:][:24]}}, \"prediction_horizon\":6, \"def_total_hours\":[2,3,3,3,3,3,3,3]}' http://localhost:5000/action/naive-mpc-optim"