emhass 0.9.0__tar.gz → 0.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. {emhass-0.9.0 → emhass-0.10.0}/CHANGELOG.md +15 -0
  2. {emhass-0.9.0 → emhass-0.10.0}/PKG-INFO +125 -19
  3. {emhass-0.9.0 → emhass-0.10.0}/README.md +124 -18
  4. {emhass-0.9.0 → emhass-0.10.0}/setup.py +1 -1
  5. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/command_line.py +392 -286
  6. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/forecast.py +21 -21
  7. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/machine_learning_regressor.py +14 -53
  8. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/optimization.py +261 -82
  9. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/retrieve_hass.py +76 -101
  10. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/utils.py +70 -128
  11. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/web_server.py +32 -7
  12. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/PKG-INFO +125 -19
  13. {emhass-0.9.0 → emhass-0.10.0}/tests/test_command_line_utils.py +2 -1
  14. {emhass-0.9.0 → emhass-0.10.0}/tests/test_forecast.py +1 -1
  15. {emhass-0.9.0 → emhass-0.10.0}/tests/test_machine_learning_forecaster.py +1 -1
  16. {emhass-0.9.0 → emhass-0.10.0}/tests/test_machine_learning_regressor.py +2 -1
  17. {emhass-0.9.0 → emhass-0.10.0}/tests/test_optimization.py +126 -2
  18. {emhass-0.9.0 → emhass-0.10.0}/tests/test_retrieve_hass.py +1 -1
  19. {emhass-0.9.0 → emhass-0.10.0}/tests/test_utils.py +3 -3
  20. {emhass-0.9.0 → emhass-0.10.0}/CODE_OF_CONDUCT.md +0 -0
  21. {emhass-0.9.0 → emhass-0.10.0}/CONTRIBUTING.md +0 -0
  22. {emhass-0.9.0 → emhass-0.10.0}/LICENSE +0 -0
  23. {emhass-0.9.0 → emhass-0.10.0}/MANIFEST.in +0 -0
  24. {emhass-0.9.0 → emhass-0.10.0}/data/data_load_cost_forecast.csv +0 -0
  25. {emhass-0.9.0 → emhass-0.10.0}/data/data_load_forecast.csv +0 -0
  26. {emhass-0.9.0 → emhass-0.10.0}/data/data_prod_price_forecast.csv +0 -0
  27. {emhass-0.9.0 → emhass-0.10.0}/data/data_train_load_clustering.pkl +0 -0
  28. {emhass-0.9.0 → emhass-0.10.0}/data/data_train_load_forecast.pkl +0 -0
  29. {emhass-0.9.0 → emhass-0.10.0}/data/data_weather_forecast.csv +0 -0
  30. {emhass-0.9.0 → emhass-0.10.0}/data/heating_prediction.csv +0 -0
  31. {emhass-0.9.0 → emhass-0.10.0}/data/opt_res_latest.csv +0 -0
  32. {emhass-0.9.0 → emhass-0.10.0}/data/opt_res_perfect_optim_cost.csv +0 -0
  33. {emhass-0.9.0 → emhass-0.10.0}/data/opt_res_perfect_optim_profit.csv +0 -0
  34. {emhass-0.9.0 → emhass-0.10.0}/data/opt_res_perfect_optim_self-consumption.csv +0 -0
  35. {emhass-0.9.0 → emhass-0.10.0}/data/test_df_final.pkl +0 -0
  36. {emhass-0.9.0 → emhass-0.10.0}/data/test_response_get_data_get_method.pbz2 +0 -0
  37. {emhass-0.9.0 → emhass-0.10.0}/data/test_response_scrapper_get_method.pbz2 +0 -0
  38. {emhass-0.9.0 → emhass-0.10.0}/data/test_response_solarforecast_get_method.pbz2 +0 -0
  39. {emhass-0.9.0 → emhass-0.10.0}/data/test_response_solcast_get_method.pbz2 +0 -0
  40. {emhass-0.9.0 → emhass-0.10.0}/pyproject.toml +0 -0
  41. {emhass-0.9.0 → emhass-0.10.0}/setup.cfg +0 -0
  42. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/__init__.py +0 -0
  43. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/data/cec_inverters.pbz2 +0 -0
  44. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/data/cec_modules.pbz2 +0 -0
  45. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/machine_learning_forecaster.py +0 -0
  46. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/advanced.html +0 -0
  47. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/basic.html +0 -0
  48. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/img/emhass_icon.png +0 -0
  49. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/img/emhass_logo_short.svg +0 -0
  50. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/img/feather-sprite.svg +0 -0
  51. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/script.js +0 -0
  52. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/static/style.css +0 -0
  53. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/templates/index.html +0 -0
  54. {emhass-0.9.0 → emhass-0.10.0}/src/emhass/templates/template.html +0 -0
  55. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/SOURCES.txt +0 -0
  56. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/dependency_links.txt +0 -0
  57. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/entry_points.txt +0 -0
  58. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/requires.txt +0 -0
  59. {emhass-0.9.0 → emhass-0.10.0}/src/emhass.egg-info/top_level.txt +0 -0
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0 - 2024-06-02
4
+ ### Improvement
5
+ - Added support for hybrid inverters
6
+ - Implemented a new `continual_publish` service that avoid the need of setting a special automation for data publish. Thanks to @GeoDerp
7
+ - Implement a deferrable load start penalty functionality. Thanks to @werdnum
8
+ - This feature also implement a `def_current_state` that can be passed at runtime to let the optimization consider that a deferrable load is currently scheduled or under operation when launching the optimization task
9
+ ### Fix
10
+ - Fixed forecast methods to treat delta_forecast higher than 1 day
11
+ - Fixed solar.forecast wrong interpolation of nan values
12
+
13
+ ## 0.9.1 - 2024-05-13
14
+ ### Fix
15
+ - Fix patch for issue with paths to modules and inverters database
16
+ - Fixed code formatting, or at least trying to keep a unique format
17
+
3
18
  ## 0.9.0 - 2024-05-10
4
19
  ### Improvement
5
20
  - On this new version we now have a new method to train a regression model using Scikit-Learn methods. This is the contribution of @gieljnssns. Check the dedicated section the documentation to this new feature: [https://emhass.readthedocs.io/en/latest/mlregressor.html](https://emhass.readthedocs.io/en/latest/mlregressor.html)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: emhass
3
- Version: 0.9.0
3
+ Version: 0.10.0
4
4
  Summary: An Energy Management System for Home Assistant
5
5
  Home-page: https://github.com/davidusb-geek/emhass
6
6
  Author: David HERNANDEZ
@@ -40,43 +40,46 @@ Requires-Dist: plotly>=5.6.0
40
40
  <strong></strong>
41
41
  </div>
42
42
  <br>
43
+
43
44
  <p align="center">
44
- <a href="https://github.com/davidusb-geek/emhass/releases">
45
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/releases">
45
46
  <img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/davidusb-geek/emhass">
46
47
  </a>
47
- <a href="https://github.com/davidusb-geek/emhass/actions">
48
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/actions">
48
49
  <img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/davidusb-geek/emhass/python-test.yml?branch=master">
49
50
  </a>
50
- <a href="https://codecov.io/github/davidusb-geek/emhass" >
51
+ <a hstyle="text-decoration:none" ref="https://codecov.io/github/davidusb-geek/emhass" >
51
52
  <img src="https://codecov.io/github/davidusb-geek/emhass/branch/master/graph/badge.svg?token=BW7KSCHN90"/>
52
53
  </a>
53
- <a href="https://github.com/davidusb-geek/emhass/blob/master/LICENSE">
54
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/blob/master/LICENSE">
54
55
  <img alt="GitHub" src="https://img.shields.io/github/license/davidusb-geek/emhass">
55
56
  </a>
56
- <a href="https://pypi.org/project/emhass/">
57
+ <a style="text-decoration:none" href="https://pypi.org/project/emhass/">
57
58
  <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/emhass">
58
59
  </a>
59
- <a href="https://pypi.org/project/emhass/">
60
+ <a style="text-decoration:none" href="https://pypi.org/project/emhass/">
60
61
  <img alt="PyPI - Status" src="https://img.shields.io/pypi/status/emhass">
61
62
  </a>
62
- <a href="https://emhass.readthedocs.io/en/latest/">
63
+ <a style="text-decoration:none" href="https://emhass.readthedocs.io/en/latest/">
63
64
  <img alt="Read the Docs" src="https://img.shields.io/readthedocs/emhass">
64
65
  </a>
65
66
  </p>
67
+
66
68
  <div align="center">
67
- <a href="https://emhass.readthedocs.io/en/latest/">
69
+ <a style="text-decoration:none" href="https://emhass.readthedocs.io/en/latest/">
68
70
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Documentation_button.svg" alt="Documentation">
69
71
  </a>
70
- <a href="https://community.home-assistant.io/t/emhass-an-energy-management-for-home-assistant/338126">
72
+ <a style="text-decoration:none" href="https://community.home-assistant.io/t/emhass-an-energy-management-for-home-assistant/338126">
71
73
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Community_button.svg" alt="Community">
72
74
  </a>
73
- <a href="https://github.com/davidusb-geek/emhass/issues">
75
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/issues">
74
76
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Issues_button.svg" alt="Issues">
75
77
  </a>
76
- <a href="https://github.com/davidusb-geek/emhass-add-on">
78
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass-add-on">
77
79
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/EMHASS_Add_on_button.svg" alt="EMHASS Add-on">
78
80
  </a>
79
81
  </div>
82
+
80
83
  <br>
81
84
  <p align="center">
82
85
  If you like this work please consider buying a coffee ;-)
@@ -282,6 +285,8 @@ sudo chmod +x /home/user/emhass/scripts/publish_data.sh
282
285
  ```
283
286
  ### Common for any installation method
284
287
 
288
+ #### Options 1, Home Assistant automate publish
289
+
285
290
  In `automations.yaml`:
286
291
  ```yaml
287
292
  - alias: EMHASS day-ahead optimization
@@ -297,9 +302,36 @@ In `automations.yaml`:
297
302
  action:
298
303
  - service: shell_command.publish_data
299
304
  ```
300
- In these automations the day-ahead optimization is performed everyday at 5:30am and the data is published every 5 minutes.
305
+ In these automation's the day-ahead optimization is performed once a day, everyday at 5:30am, and the data *(output of automation)* is published every 5 minutes.
306
+
307
+ #### Option 2, EMHASS automate publish
301
308
 
302
- The final action will be to link a sensor value in Home Assistant to control the switch of a desired controllable load. For example imagine that I want to control my water heater and that the `publish-data` action is publishing the optimized value of a deferrable load that I want to be linked to my water heater desired behavior. In this case we could use an automation like this one below to control the desired real switch:
309
+ In `automations.yaml`:
310
+ ```yaml
311
+ - alias: EMHASS day-ahead optimization
312
+ trigger:
313
+ platform: time
314
+ at: '05:30:00'
315
+ action:
316
+ - service: shell_command.dayahead_optim
317
+ - service: shell_command.publish_data
318
+ ```
319
+ in configuration page/`config_emhass.yaml`
320
+ ```json
321
+ "method_ts_round": "first"
322
+ "continual_publish": true
323
+ ```
324
+ In this automation the day-ahead optimization is performed once a day, everyday at 5:30am.
325
+ If the `freq` parameter is set to `30` *(default)* in the configuration, the results of the day-ahead optimization will generate 48 values *(for each entity)*, a value for each 30 minutes in a day *(i.e. 24 hrs x 2)*.
326
+
327
+ Setting the parameter `continual_publish` to `true` in the configuration page, will allow EMHASS to store the optimization results as entities/sensors into seperate json files. `continual_publish` will periodically (every `freq` amount of minutes) run a publish, and publish the optimization results of each generated entities/sensors to Home Assistant. The current state of the sensor/entity being updated every time publish runs, selecting one of the 48 stored values, by comparing the stored values timestamps, the current timestamp and [`"method_ts_round": "first"`](#the-publish-data-specificities) to select the optimal stored value for the current state.
328
+
329
+ option 1 and 2 are very similar, however option 2 (`continual_publish`) will require a cpu thread to constantly be run inside of EMHASS, lowering efficiency. The reason why you may pick one over the other is explained in more detail bellow in [continual_publish](#continual_publish-emhass-automation).
330
+
331
+ Lastly, we can link a EMHASS published entities/sensor's current state to a Home Assistant entity on/off switch, controlling a desired controllable load.
332
+ For example, imagine that I want to control my water heater. I can use a published `deferrable` EMHASS entity to control my water heaters desired behavior. In this case, we could use an automation like below, to control the desired water heater on and off:
333
+
334
+ on:
303
335
  ```yaml
304
336
  automation:
305
337
  - alias: Water Heater Optimized ON
@@ -314,7 +346,7 @@ automation:
314
346
  - service: homeassistant.turn_on
315
347
  entity_id: switch.water_heater_switch
316
348
  ```
317
- A second automation should be used to turn off the switch:
349
+ off:
318
350
  ```yaml
319
351
  automation:
320
352
  - alias: Water Heater Optimized OFF
@@ -329,14 +361,15 @@ automation:
329
361
  - service: homeassistant.turn_off
330
362
  entity_id: switch.water_heater_switch
331
363
  ```
364
+ The result of these automation's will turn on and off the Home Assistant entity `switch.water_heater_switch` using the current state from the EMHASS entity `sensor.p_deferrable0`. `sensor.p_deferrable0` being the entity generated from the EMHASS day-ahead optimization and published by examples above. The `sensor.p_deferrable0` entity current state being updated every 30 minutes (or `freq` minutes) via a automated publish option 1 or 2. *(selecting one of the 48 stored data values)*
332
365
 
333
366
  ## The publish-data specificities
334
367
 
335
- The `publish-data` command will push to Home Assistant the optimization results for each deferrable load defined in the configuration. For example if you have defined two deferrable loads, then the command will publish `sensor.p_deferrable0` and `sensor.p_deferrable1` to Home Assistant. When the `dayahead-optim` is launched, after the optimization, a csv file will be saved on disk. The `publish-data` command will load the latest csv file and look for the closest timestamp that match the current time using the `datetime.now()` method in Python. This means that if EMHASS is configured for 30min time step optimizations, the csv will be saved with timestamps 00:00, 00:30, 01:00, 01:30, ... and so on. If the current time is 00:05, then the closest timestamp of the optimization results that will be published is 00:00. If the current time is 00:25, then the closest timestamp of the optimization results that will be published is 00:30.
368
+ `publish-data` (which is either run manually, or automatically via `continual_publish` or Home Assistant automation), will push the optimization results to Home Assistant for each deferrable load defined in the configuration. For example if you have defined two deferrable loads, then the command will publish `sensor.p_deferrable0` and `sensor.p_deferrable1` to Home Assistant. When the `dayahead-optim` is launched, after the optimization, either entity json files or a csv file will be saved on disk. The `publish-data` command will load the latest csv/json files to look for the closest timestamp that match the current time using the `datetime.now()` method in Python. This means that if EMHASS is configured for 30min time step optimizations, the csv/json will be saved with timestamps 00:00, 00:30, 01:00, 01:30, ... and so on. If the current time is 00:05, and parameter `method_ts_round` is set to `nearest` in the configuration, then the closest timestamp of the optimization results that will be published is 00:00. If the current time is 00:25, then the closest timestamp of the optimization results that will be published is 00:30.
336
369
 
337
370
  The `publish-data` command will also publish PV and load forecast data on sensors `p_pv_forecast` and `p_load_forecast`. If using a battery, then the battery optimized power and the SOC will be published on sensors `p_batt_forecast` and `soc_batt_forecast`. On these sensors the future values are passed as nested attributes.
338
371
 
339
- It is possible to provide custm sensor names for all the data exported by the `publish-data` command. For this, when using the `publish-data` endpoint just add some runtime parameters as dictionaries like this:
372
+ If you run publish manually *(or via a Home Assistant Automation)*, it is possible to provide custom sensor names for all the data exported by the `publish-data` command. For this, when using the `publish-data` endpoint we can just add some runtime parameters as dictionaries like this:
340
373
  ```yaml
341
374
  shell_command:
342
375
  publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"custom_load_forecast_id\": {\"entity_id\": \"sensor.p_load_forecast\", \"unit_of_measurement\": \"W\", \"friendly_name\": \"Load Power Forecast\"}}' http://localhost:5000/action/publish-data"
@@ -384,12 +417,85 @@ In EMHASS we have basically 4 forecasts to deal with:
384
417
 
385
418
  - PV production selling price forecast: at what price are you selling your excess PV production on the next 24h. This is given in EUR/kWh.
386
419
 
387
- The sensor containing the load data should be specified in parameter `var_load` in the configuration file. As we want to optimize the household energies, when need to forecast the load power conumption. The default method for this is a naive approach using 1-day persistence. The load data variable should not contain the data from the deferrable loads themselves. For example, lets say that you set your deferrable load to be the washing machine. The variable that you should enter in EMHASS will be: `var_load: 'sensor.power_load_no_var_loads'` and `sensor.power_load_no_var_loads = sensor.power_load - sensor.power_washing_machine`. This is supposing that the overall load of your house is contained in variable: `sensor.power_load`. The sensor `sensor.power_load_no_var_loads` can be easily created with a new template sensor in Home Assistant.
420
+ The sensor containing the load data should be specified in parameter `var_load` in the configuration file. As we want to optimize the household energies, when need to forecast the load power consumption. The default method for this is a naive approach using 1-day persistence. The load data variable should not contain the data from the deferrable loads themselves. For example, lets say that you set your deferrable load to be the washing machine. The variable that you should enter in EMHASS will be: `var_load: 'sensor.power_load_no_var_loads'` and `sensor.power_load_no_var_loads = sensor.power_load - sensor.power_washing_machine`. This is supposing that the overall load of your house is contained in variable: `sensor.power_load`. The sensor `sensor.power_load_no_var_loads` can be easily created with a new template sensor in Home Assistant.
388
421
 
389
422
  If you are implementing a MPC controller, then you should also need to provide some data at the optimization runtime using the key `runtimeparams`.
390
423
 
391
424
  The valid values to pass for both forecast data and MPC related data are explained below.
392
425
 
426
+ ### Alternative publish methods
427
+ Due to the flexibility of EMHASS, multiple different approaches to publishing the optimization results have been created. Select a option that best meets your use case:
428
+
429
+ #### publish last optimization *(manual)*
430
+ By default, running an optimization in EMHASS will output the results into the csv file: `data_path/opt_res_latest.csv` *(overriding the existing data on that file)*. We run the publish command to publish the last optimization saved in the `opt_res_latest.csv`:
431
+ ```bash
432
+ # RUN dayahead
433
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/dayahead-optim
434
+ # Then publish teh results of dayahead
435
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/publish-data
436
+ ```
437
+ *Note, the published entities from the publish-data action will not automatically update the entities current state (current state being used to check when to turn on and off appliances via Home Assistant automatons). To update the EMHASS entities state, another publish would have to be re-run later when the current time matches the next values timestamp (E.g every 30 minutes). See examples bellow for methods to automate the publish-action.*
438
+
439
+ #### continual_publish *(EMHASS Automation)*
440
+ As discussed in [Common for any installation method - option 2](#option-2-emhass-automate-publish), setting `continual_publish` to `true` in the configuration saves the output of the optimization into the `data_path/entities` folder *(a .json file for each sensor/entity)*. A constant loop (in `freq` minutes) will run, observe the .json files in that folder, and publish the saved files periodically (updating the current state of the entity by comparing date.now with the saved data value timestamps).
441
+
442
+ For users that wish to run multiple different optimizations, you can set the runtime parameter: `publish_prefix` to something like: `"mpc_"` or `"dh_"`. This will generate unique entity_id names per optimization and save these unique entities as separate files in the folder. All the entity files will then be updated when the next loop iteration runs. If a different `freq` integer was passed as a runtime parameter in an optimization, the `continual_publish` loop will be based on the lowest `freq` saved. An example:
443
+
444
+ ```bash
445
+ # RUN dayahead, with freq=30 (default), prefix=dh_
446
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
447
+ # RUN MPC, with freq=5, prefix=mpc_
448
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
449
+ ```
450
+ This will tell continual_publish to loop every 5 minutes based on the freq passed in MPC. All entities from the output of dayahead "dh_" and MPC "mpc_" will be published every 5 minutes.
451
+
452
+ </br>
453
+
454
+ *It is recommended to use the 2 other options bellow once you have a more advance understanding of EMHASS and/or Home Assistant.*
455
+
456
+ #### Mixture of continual_publish and manual *(Home Assistant Automation for Publish)*
457
+
458
+ You can choose to save one optimization for continual_publish and bypass another optimization by setting `"continual_publish":false` runtime parameter:
459
+ ```bash
460
+ # RUN dayahead, with freq=30 (default), prefix=dh_, included into continual_publish
461
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
462
+
463
+ # RUN MPC, with freq=5, prefix=mpc_, Manually publish, excluded from continual_publish loop
464
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"continual_publish":false,"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
465
+ # Publish MPC output
466
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/publish-data
467
+ ```
468
+ This example saves the dayahead optimization into `data_path/entities` as .json files, being included in the `continutal_publish` loop (publishing every 30 minutes). The MPC optimization will not be saved in `data_path/entities`, and therefore only into `data_path/opt_res_latest.csv`. Requiring a publish-data action to be run manually (or via a Home Assistant) Automation for the MPC results.
469
+
470
+ #### Manual *(Home Assistant Automation for Publish)*
471
+
472
+ For users who wish to have full control of exactly when they will like to run a publish and have the ability to save multiple different optimizations. The `entity_save` runtime parameter has been created to save the optimization output entities to .json files whilst `continual_publish` is set to `false` in the configuration. Allowing the user to reference the saved .json files manually via a publish:
473
+
474
+ in configuration page/`config_emhass.yaml` :
475
+ ```json
476
+ "continual_publish": false
477
+ ```
478
+ POST action :
479
+ ```bash
480
+ # RUN dayahead, with freq=30 (default), prefix=dh_, save entity
481
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true, "publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
482
+ # RUN MPC, with freq=5, prefix=mpc_, save entity
483
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true", "freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
484
+ ```
485
+ You can then reference these .json saved entities via their `publish_prefix`. Include the same `publish_prefix` in the `publish_data` action:
486
+ ```bash
487
+ #Publish the MPC optimization ran above
488
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"mpc_"}' http://localhost:5000/action/publish-data
489
+ ```
490
+ This will publish all entities from the MPC (_mpc) optimization above.
491
+ </br>
492
+ Alternatively, you can choose to publish all the saved files .json files with `publish_prefix` = all:
493
+ ```bash
494
+ #Publish all saved entities
495
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"all"}' http://localhost:5000/action/publish-data
496
+ ```
497
+ This action will publish the dayahead (_dh) and MPC (_mpc) optimization results from the optimizations above.
498
+
393
499
  ### Forecast data
394
500
 
395
501
  It is possible to provide EMHASS with your own forecast data. For this just add the data as list of values to a data dictionary during the call to `emhass` using the `runtimeparams` option.
@@ -488,7 +594,7 @@ Check the dedicated section in the documentation here: [https://emhass.readthedo
488
594
 
489
595
  ## Development
490
596
 
491
- Pull request are very much accepted on this project. For development you can find some instructions here [Development](https://emhass.readthedocs.io/en/latest/develop.html)
597
+ Pull request are very much accepted on this project. For development you can find some instructions here [Development](https://emhass.readthedocs.io/en/latest/develop.html).
492
598
 
493
599
  ## Troubleshooting
494
600
 
@@ -5,43 +5,46 @@
5
5
  <strong></strong>
6
6
  </div>
7
7
  <br>
8
+
8
9
  <p align="center">
9
- <a href="https://github.com/davidusb-geek/emhass/releases">
10
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/releases">
10
11
  <img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/davidusb-geek/emhass">
11
12
  </a>
12
- <a href="https://github.com/davidusb-geek/emhass/actions">
13
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/actions">
13
14
  <img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/davidusb-geek/emhass/python-test.yml?branch=master">
14
15
  </a>
15
- <a href="https://codecov.io/github/davidusb-geek/emhass" >
16
+ <a hstyle="text-decoration:none" ref="https://codecov.io/github/davidusb-geek/emhass" >
16
17
  <img src="https://codecov.io/github/davidusb-geek/emhass/branch/master/graph/badge.svg?token=BW7KSCHN90"/>
17
18
  </a>
18
- <a href="https://github.com/davidusb-geek/emhass/blob/master/LICENSE">
19
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/blob/master/LICENSE">
19
20
  <img alt="GitHub" src="https://img.shields.io/github/license/davidusb-geek/emhass">
20
21
  </a>
21
- <a href="https://pypi.org/project/emhass/">
22
+ <a style="text-decoration:none" href="https://pypi.org/project/emhass/">
22
23
  <img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/emhass">
23
24
  </a>
24
- <a href="https://pypi.org/project/emhass/">
25
+ <a style="text-decoration:none" href="https://pypi.org/project/emhass/">
25
26
  <img alt="PyPI - Status" src="https://img.shields.io/pypi/status/emhass">
26
27
  </a>
27
- <a href="https://emhass.readthedocs.io/en/latest/">
28
+ <a style="text-decoration:none" href="https://emhass.readthedocs.io/en/latest/">
28
29
  <img alt="Read the Docs" src="https://img.shields.io/readthedocs/emhass">
29
30
  </a>
30
31
  </p>
32
+
31
33
  <div align="center">
32
- <a href="https://emhass.readthedocs.io/en/latest/">
34
+ <a style="text-decoration:none" href="https://emhass.readthedocs.io/en/latest/">
33
35
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Documentation_button.svg" alt="Documentation">
34
36
  </a>
35
- <a href="https://community.home-assistant.io/t/emhass-an-energy-management-for-home-assistant/338126">
37
+ <a style="text-decoration:none" href="https://community.home-assistant.io/t/emhass-an-energy-management-for-home-assistant/338126">
36
38
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Community_button.svg" alt="Community">
37
39
  </a>
38
- <a href="https://github.com/davidusb-geek/emhass/issues">
40
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass/issues">
39
41
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/Issues_button.svg" alt="Issues">
40
42
  </a>
41
- <a href="https://github.com/davidusb-geek/emhass-add-on">
43
+ <a style="text-decoration:none" href="https://github.com/davidusb-geek/emhass-add-on">
42
44
  <img src="https://raw.githubusercontent.com/davidusb-geek/emhass/master/docs/images/EMHASS_Add_on_button.svg" alt="EMHASS Add-on">
43
45
  </a>
44
46
  </div>
47
+
45
48
  <br>
46
49
  <p align="center">
47
50
  If you like this work please consider buying a coffee ;-)
@@ -247,6 +250,8 @@ sudo chmod +x /home/user/emhass/scripts/publish_data.sh
247
250
  ```
248
251
  ### Common for any installation method
249
252
 
253
+ #### Options 1, Home Assistant automate publish
254
+
250
255
  In `automations.yaml`:
251
256
  ```yaml
252
257
  - alias: EMHASS day-ahead optimization
@@ -262,9 +267,36 @@ In `automations.yaml`:
262
267
  action:
263
268
  - service: shell_command.publish_data
264
269
  ```
265
- In these automations the day-ahead optimization is performed everyday at 5:30am and the data is published every 5 minutes.
270
+ In these automation's the day-ahead optimization is performed once a day, everyday at 5:30am, and the data *(output of automation)* is published every 5 minutes.
271
+
272
+ #### Option 2, EMHASS automate publish
266
273
 
267
- The final action will be to link a sensor value in Home Assistant to control the switch of a desired controllable load. For example imagine that I want to control my water heater and that the `publish-data` action is publishing the optimized value of a deferrable load that I want to be linked to my water heater desired behavior. In this case we could use an automation like this one below to control the desired real switch:
274
+ In `automations.yaml`:
275
+ ```yaml
276
+ - alias: EMHASS day-ahead optimization
277
+ trigger:
278
+ platform: time
279
+ at: '05:30:00'
280
+ action:
281
+ - service: shell_command.dayahead_optim
282
+ - service: shell_command.publish_data
283
+ ```
284
+ in configuration page/`config_emhass.yaml`
285
+ ```json
286
+ "method_ts_round": "first"
287
+ "continual_publish": true
288
+ ```
289
+ In this automation the day-ahead optimization is performed once a day, everyday at 5:30am.
290
+ If the `freq` parameter is set to `30` *(default)* in the configuration, the results of the day-ahead optimization will generate 48 values *(for each entity)*, a value for each 30 minutes in a day *(i.e. 24 hrs x 2)*.
291
+
292
+ Setting the parameter `continual_publish` to `true` in the configuration page, will allow EMHASS to store the optimization results as entities/sensors into seperate json files. `continual_publish` will periodically (every `freq` amount of minutes) run a publish, and publish the optimization results of each generated entities/sensors to Home Assistant. The current state of the sensor/entity being updated every time publish runs, selecting one of the 48 stored values, by comparing the stored values timestamps, the current timestamp and [`"method_ts_round": "first"`](#the-publish-data-specificities) to select the optimal stored value for the current state.
293
+
294
+ option 1 and 2 are very similar, however option 2 (`continual_publish`) will require a cpu thread to constantly be run inside of EMHASS, lowering efficiency. The reason why you may pick one over the other is explained in more detail bellow in [continual_publish](#continual_publish-emhass-automation).
295
+
296
+ Lastly, we can link a EMHASS published entities/sensor's current state to a Home Assistant entity on/off switch, controlling a desired controllable load.
297
+ For example, imagine that I want to control my water heater. I can use a published `deferrable` EMHASS entity to control my water heaters desired behavior. In this case, we could use an automation like below, to control the desired water heater on and off:
298
+
299
+ on:
268
300
  ```yaml
269
301
  automation:
270
302
  - alias: Water Heater Optimized ON
@@ -279,7 +311,7 @@ automation:
279
311
  - service: homeassistant.turn_on
280
312
  entity_id: switch.water_heater_switch
281
313
  ```
282
- A second automation should be used to turn off the switch:
314
+ off:
283
315
  ```yaml
284
316
  automation:
285
317
  - alias: Water Heater Optimized OFF
@@ -294,14 +326,15 @@ automation:
294
326
  - service: homeassistant.turn_off
295
327
  entity_id: switch.water_heater_switch
296
328
  ```
329
+ The result of these automation's will turn on and off the Home Assistant entity `switch.water_heater_switch` using the current state from the EMHASS entity `sensor.p_deferrable0`. `sensor.p_deferrable0` being the entity generated from the EMHASS day-ahead optimization and published by examples above. The `sensor.p_deferrable0` entity current state being updated every 30 minutes (or `freq` minutes) via a automated publish option 1 or 2. *(selecting one of the 48 stored data values)*
297
330
 
298
331
  ## The publish-data specificities
299
332
 
300
- The `publish-data` command will push to Home Assistant the optimization results for each deferrable load defined in the configuration. For example if you have defined two deferrable loads, then the command will publish `sensor.p_deferrable0` and `sensor.p_deferrable1` to Home Assistant. When the `dayahead-optim` is launched, after the optimization, a csv file will be saved on disk. The `publish-data` command will load the latest csv file and look for the closest timestamp that match the current time using the `datetime.now()` method in Python. This means that if EMHASS is configured for 30min time step optimizations, the csv will be saved with timestamps 00:00, 00:30, 01:00, 01:30, ... and so on. If the current time is 00:05, then the closest timestamp of the optimization results that will be published is 00:00. If the current time is 00:25, then the closest timestamp of the optimization results that will be published is 00:30.
333
+ `publish-data` (which is either run manually, or automatically via `continual_publish` or Home Assistant automation), will push the optimization results to Home Assistant for each deferrable load defined in the configuration. For example if you have defined two deferrable loads, then the command will publish `sensor.p_deferrable0` and `sensor.p_deferrable1` to Home Assistant. When the `dayahead-optim` is launched, after the optimization, either entity json files or a csv file will be saved on disk. The `publish-data` command will load the latest csv/json files to look for the closest timestamp that match the current time using the `datetime.now()` method in Python. This means that if EMHASS is configured for 30min time step optimizations, the csv/json will be saved with timestamps 00:00, 00:30, 01:00, 01:30, ... and so on. If the current time is 00:05, and parameter `method_ts_round` is set to `nearest` in the configuration, then the closest timestamp of the optimization results that will be published is 00:00. If the current time is 00:25, then the closest timestamp of the optimization results that will be published is 00:30.
301
334
 
302
335
  The `publish-data` command will also publish PV and load forecast data on sensors `p_pv_forecast` and `p_load_forecast`. If using a battery, then the battery optimized power and the SOC will be published on sensors `p_batt_forecast` and `soc_batt_forecast`. On these sensors the future values are passed as nested attributes.
303
336
 
304
- It is possible to provide custm sensor names for all the data exported by the `publish-data` command. For this, when using the `publish-data` endpoint just add some runtime parameters as dictionaries like this:
337
+ If you run publish manually *(or via a Home Assistant Automation)*, it is possible to provide custom sensor names for all the data exported by the `publish-data` command. For this, when using the `publish-data` endpoint we can just add some runtime parameters as dictionaries like this:
305
338
  ```yaml
306
339
  shell_command:
307
340
  publish_data: "curl -i -H \"Content-Type:application/json\" -X POST -d '{\"custom_load_forecast_id\": {\"entity_id\": \"sensor.p_load_forecast\", \"unit_of_measurement\": \"W\", \"friendly_name\": \"Load Power Forecast\"}}' http://localhost:5000/action/publish-data"
@@ -349,12 +382,85 @@ In EMHASS we have basically 4 forecasts to deal with:
349
382
 
350
383
  - PV production selling price forecast: at what price are you selling your excess PV production on the next 24h. This is given in EUR/kWh.
351
384
 
352
- The sensor containing the load data should be specified in parameter `var_load` in the configuration file. As we want to optimize the household energies, when need to forecast the load power conumption. The default method for this is a naive approach using 1-day persistence. The load data variable should not contain the data from the deferrable loads themselves. For example, lets say that you set your deferrable load to be the washing machine. The variable that you should enter in EMHASS will be: `var_load: 'sensor.power_load_no_var_loads'` and `sensor.power_load_no_var_loads = sensor.power_load - sensor.power_washing_machine`. This is supposing that the overall load of your house is contained in variable: `sensor.power_load`. The sensor `sensor.power_load_no_var_loads` can be easily created with a new template sensor in Home Assistant.
385
+ The sensor containing the load data should be specified in parameter `var_load` in the configuration file. As we want to optimize the household energies, when need to forecast the load power consumption. The default method for this is a naive approach using 1-day persistence. The load data variable should not contain the data from the deferrable loads themselves. For example, lets say that you set your deferrable load to be the washing machine. The variable that you should enter in EMHASS will be: `var_load: 'sensor.power_load_no_var_loads'` and `sensor.power_load_no_var_loads = sensor.power_load - sensor.power_washing_machine`. This is supposing that the overall load of your house is contained in variable: `sensor.power_load`. The sensor `sensor.power_load_no_var_loads` can be easily created with a new template sensor in Home Assistant.
353
386
 
354
387
  If you are implementing a MPC controller, then you should also need to provide some data at the optimization runtime using the key `runtimeparams`.
355
388
 
356
389
  The valid values to pass for both forecast data and MPC related data are explained below.
357
390
 
391
+ ### Alternative publish methods
392
+ Due to the flexibility of EMHASS, multiple different approaches to publishing the optimization results have been created. Select a option that best meets your use case:
393
+
394
+ #### publish last optimization *(manual)*
395
+ By default, running an optimization in EMHASS will output the results into the csv file: `data_path/opt_res_latest.csv` *(overriding the existing data on that file)*. We run the publish command to publish the last optimization saved in the `opt_res_latest.csv`:
396
+ ```bash
397
+ # RUN dayahead
398
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/dayahead-optim
399
+ # Then publish teh results of dayahead
400
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/publish-data
401
+ ```
402
+ *Note, the published entities from the publish-data action will not automatically update the entities current state (current state being used to check when to turn on and off appliances via Home Assistant automatons). To update the EMHASS entities state, another publish would have to be re-run later when the current time matches the next values timestamp (E.g every 30 minutes). See examples bellow for methods to automate the publish-action.*
403
+
404
+ #### continual_publish *(EMHASS Automation)*
405
+ As discussed in [Common for any installation method - option 2](#option-2-emhass-automate-publish), setting `continual_publish` to `true` in the configuration saves the output of the optimization into the `data_path/entities` folder *(a .json file for each sensor/entity)*. A constant loop (in `freq` minutes) will run, observe the .json files in that folder, and publish the saved files periodically (updating the current state of the entity by comparing date.now with the saved data value timestamps).
406
+
407
+ For users that wish to run multiple different optimizations, you can set the runtime parameter: `publish_prefix` to something like: `"mpc_"` or `"dh_"`. This will generate unique entity_id names per optimization and save these unique entities as separate files in the folder. All the entity files will then be updated when the next loop iteration runs. If a different `freq` integer was passed as a runtime parameter in an optimization, the `continual_publish` loop will be based on the lowest `freq` saved. An example:
408
+
409
+ ```bash
410
+ # RUN dayahead, with freq=30 (default), prefix=dh_
411
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
412
+ # RUN MPC, with freq=5, prefix=mpc_
413
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
414
+ ```
415
+ This will tell continual_publish to loop every 5 minutes based on the freq passed in MPC. All entities from the output of dayahead "dh_" and MPC "mpc_" will be published every 5 minutes.
416
+
417
+ </br>
418
+
419
+ *It is recommended to use the 2 other options bellow once you have a more advance understanding of EMHASS and/or Home Assistant.*
420
+
421
+ #### Mixture of continual_publish and manual *(Home Assistant Automation for Publish)*
422
+
423
+ You can choose to save one optimization for continual_publish and bypass another optimization by setting `"continual_publish":false` runtime parameter:
424
+ ```bash
425
+ # RUN dayahead, with freq=30 (default), prefix=dh_, included into continual_publish
426
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
427
+
428
+ # RUN MPC, with freq=5, prefix=mpc_, Manually publish, excluded from continual_publish loop
429
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"continual_publish":false,"freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
430
+ # Publish MPC output
431
+ curl -i -H 'Content-Type:application/json' -X POST -d {} http://localhost:5000/action/publish-data
432
+ ```
433
+ This example saves the dayahead optimization into `data_path/entities` as .json files, being included in the `continutal_publish` loop (publishing every 30 minutes). The MPC optimization will not be saved in `data_path/entities`, and therefore only into `data_path/opt_res_latest.csv`. Requiring a publish-data action to be run manually (or via a Home Assistant) Automation for the MPC results.
434
+
435
+ #### Manual *(Home Assistant Automation for Publish)*
436
+
437
+ For users who wish to have full control of exactly when they will like to run a publish and have the ability to save multiple different optimizations. The `entity_save` runtime parameter has been created to save the optimization output entities to .json files whilst `continual_publish` is set to `false` in the configuration. Allowing the user to reference the saved .json files manually via a publish:
438
+
439
+ in configuration page/`config_emhass.yaml` :
440
+ ```json
441
+ "continual_publish": false
442
+ ```
443
+ POST action :
444
+ ```bash
445
+ # RUN dayahead, with freq=30 (default), prefix=dh_, save entity
446
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true, "publish_prefix":"dh_"}' http://localhost:5000/action/dayahead-optim
447
+ # RUN MPC, with freq=5, prefix=mpc_, save entity
448
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"entity_save": true", "freq":5,"publish_prefix":"mpc_"}' http://localhost:5000/action/naive-mpc-optim
449
+ ```
450
+ You can then reference these .json saved entities via their `publish_prefix`. Include the same `publish_prefix` in the `publish_data` action:
451
+ ```bash
452
+ #Publish the MPC optimization ran above
453
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"mpc_"}' http://localhost:5000/action/publish-data
454
+ ```
455
+ This will publish all entities from the MPC (_mpc) optimization above.
456
+ </br>
457
+ Alternatively, you can choose to publish all the saved files .json files with `publish_prefix` = all:
458
+ ```bash
459
+ #Publish all saved entities
460
+ curl -i -H 'Content-Type:application/json' -X POST -d '{"publish_prefix":"all"}' http://localhost:5000/action/publish-data
461
+ ```
462
+ This action will publish the dayahead (_dh) and MPC (_mpc) optimization results from the optimizations above.
463
+
358
464
  ### Forecast data
359
465
 
360
466
  It is possible to provide EMHASS with your own forecast data. For this just add the data as list of values to a data dictionary during the call to `emhass` using the `runtimeparams` option.
@@ -453,7 +559,7 @@ Check the dedicated section in the documentation here: [https://emhass.readthedo
453
559
 
454
560
  ## Development
455
561
 
456
- Pull request are very much accepted on this project. For development you can find some instructions here [Development](https://emhass.readthedocs.io/en/latest/develop.html)
562
+ Pull request are very much accepted on this project. For development you can find some instructions here [Development](https://emhass.readthedocs.io/en/latest/develop.html).
457
563
 
458
564
  ## Troubleshooting
459
565
 
@@ -19,7 +19,7 @@ long_description = (here / 'README.md').read_text(encoding='utf-8')
19
19
 
20
20
  setup(
21
21
  name='emhass', # Required
22
- version='0.9.0', # Required
22
+ version='0.10.0', # Required
23
23
  description='An Energy Management System for Home Assistant', # Optional
24
24
  long_description=long_description, # Optional
25
25
  long_description_content_type='text/markdown', # Optional (see note above)