davidusb-geek / emhass

emhass: Energy Management for Home Assistant, is a Python module designed to optimize your home energy interfacing with Home Assistant.
MIT License
260 stars 51 forks source link

continual_publish service #284

Closed GeoDerp closed 1 month ago

GeoDerp commented 1 month ago

continual_publish

A new parameter continual_publish (boolean) has been generated and will:


This Pull Request is a "functional" proof of concept. Feel free to comment, review or commit any pull requests. I will likely refine this post and/or the code later.

Operation Example:

continual_publish drawio


Notes

GeoDerp commented 1 month ago

Some other images for reference

.json files generated from operation example

Screenshot from 2024-05-15 20-53-17

Example of entity

Screenshot from 2024-05-15 20-53-46 Screenshot from 2024-05-15 20-53-28

Example of logs

Screenshot from 2024-05-15 20-54-07

davidusb-geek commented 1 month ago

Hi @GeoDerp, this seems nice! So the publish action is done automatically. The freq parameters is not the same as in the config.yaml:

retrieve_hass_conf:
  freq: 30 # The time step to resample retrieved data from hass in minutes

?? If so, then probably give it another name to avoid confusion. Ex: freq_publish?

A comment. This maybe the opportunity to solve this issue about unique IDs: https://github.com/davidusb-geek/emhass-add-on/issues/91

GeoDerp commented 1 month ago

Hi @GeoDerp, this seems nice! So the publish action is done automatically. The freq parameters is not the same as in the config.yaml:

retrieve_hass_conf:
  freq: 30 # The time step to resample retrieved data from hass in minutes

?? If so, then probably give it another name to avoid confusion. Ex: freq_publish?

A comment. This maybe the opportunity to solve this issue about unique IDs: davidusb-geek/emhass-add-on#91

We can defiantly set up a freq_publish parameter. The loop frequency is initially set up by the frequency provided by freq in config.yaml. It is assumed that freq may change depending on a combination of MPC and dayahead calls. (for instance dayahead may be 30min freq and MPC is 1 minute) Therefore the metadata logs the lowest freq used, then the loop is set to that. Its very mutch unnecessary and we can just set a freq_publish parameter, or set a fixed loop of 1 minute.

Edit: oh sorry, yeah the publish is done automatically.

GeoDerp commented 1 month ago

I might see how difficult it would be to fix the unique_id issue

davidusb-geek commented 1 month ago

We can defiantly set up a freq_publish parameter.

No that's ok, I thought that it was a different parameters. But is the same sol let's keep freq

GeoDerp commented 1 month ago

@purcell-lab , whats your take on the Pull Request?

purcell-lab commented 1 month ago

This functionality is very welcome in 99% of cases I almost always have a publish command following an optimisation command. As I want my automations to take action as soon as a new set of optim results are available. In your flow diagram this is covered by the publish_data function. In the case if MPC is run every 1 or 7 minutes, it will immediately publish results without awaiting the loop?

The other case is when we cross a time step boundary (e g minute /30) in many cases there is a new set of data awaiting publication from the last optim run, which should be published immediately. Is this the function of continual_publish? Does this need to run every minute or just every time step?

GeoDerp commented 1 month ago

Sorry for my delay. I created a video explaining on the progress of the PR (forgive my tiredness). Ill merge the latest changes tomorrow when I'm more awake.

continual_publish explaination.

Side note. I am thinking of creating a couple of videos explaining my development process, and EMHASS workflow (once its finalized). Let me know if you like this video and ill consider.

davidusb-geek commented 1 month ago

Wow those kind of videos are really genius! That type of tutorial will help a lot of people for first setups for example. Great job! Definitely go for them if you're willing, to explain the EMHASS workflow.

For this PR it was already great with that flow diagram at the beginning, the video is a great to understand that even better. How will we deal with default behavior? It could be great to set continual_publish by default to True right? But then that may somehow collide with our current automations to publish data?

GeoDerp commented 1 month ago

Just a note, the README will likely need to be improved more before the merge. I may have also missed some documentation in the README or docs, that would require adjustment for this PR . All help will be appreciated.

How will we deal with default behavior?

I agree, I think its best to leave the continual_publish to false by default for the existing EMHASS users. However, I have adjusted the README (Common for any installation method) examples to include the continual_publish functionality as a publish option. Currently presenting both the old and the new option for the base day-ahead example. I can remove a option on request.

@davidusb-geek , Let me know if you would like unitests generated for this PR.

GeoDerp commented 1 month ago

Thank my Dad for noticing the DateTime Issue while testing. Bug Fixed.

davidusb-geek commented 1 month ago

Hi @GeoDerp, is this good to go?

GeoDerp commented 1 month ago

Hi @GeoDerp, is this good to go?

Code should be good to go. I would recommend reading the README file first just to see if you're happy with it. (Definitely put more working into the code than the readme) I also haven't added any relevant unitests. (not sure if it's required for this integration) Happy to look into some of requested.