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
272 stars 54 forks source link

Add a function to predict a value from a csv file. #147

Closed gieljnssns closed 4 months ago

gieljnssns commented 7 months ago

The story behind this pull request. I keep a CSV file in which I store data from which I want to predict the number of heating hours. I first tried to do this via a custom_component for home-assistant, but apparently it is not possible to install scikit-learn. Since the result of my prediction is to be used in emhass and the necessary dependencies are already installed in emhass, I decided to go this way.

This pull request contains a new method csv-predict with new parameters, here is an example of a rest command in home-assistant

predict_heating:
  url: http://localhost:5001/action/csv-predict
  method: POST
  content_type: "application/json"
  payload: >-
    {
      "csv_file": "prediction.csv",
      "independent_variables":["dd", "solar"],
      "dependent_variable": "hour",
      "sklearn_model": "LinearRegression",
      "csv_predict_entity_id": "sensor.voorspelde_uren",
      "csv_predict_unit_of_measurement": "h",
      "csv_predict_friendly_name": "Voorspelde uren",
      "new_values": [{{states("sensor.degree_day_prediction")}}, {{states("sensor.solcast_solaredge_forecast_today")}}]
    }

If you are open to accepting this pull request, I will also take the time to write some documentation. And if necessary, I would also like to try writing some tests.

Here is also a used CSV file. prediction.csv

gieljnssns commented 4 months ago
vscode ➜ /workspaces/emhass (master) $ git remote add david https://github.com/davidusb-geek/emhass.git
error: remote david already exists.
gieljnssns commented 4 months ago

I think the best I can do is closing this PR and do it again?

GeoDerp commented 4 months ago
vscode ➜ /workspaces/emhass (master) $ git remote add david https://github.com/davidusb-geek/emhass.git
error: remote david already exists.
git remote rm david

Having a remote that's the origin repository is a good way (my uneducated option ) to fetch and pull in the latest commits to merge or make a new branch. Feel free to use something like this in the future 😁.

Vs code has GUI ways to do this I believe.