titilambert / pyhydroquebec

DEPRECATED - Get your consumption data from your HydroQuebec account (www.hydroquebec.com)
Apache License 2.0
94 stars 45 forks source link

Integration back to HomeAssistant #49

Open llluis opened 4 years ago

llluis commented 4 years ago

Hi @titilambert, First of all, thanks for your work!

What's your plan to integrate this back to HA? I created a custom component and am successfully polling my daily consumption back to HA (using parts of the old official component). We know this couldn't become an official integration anymore, but are we gonna provide a custom template?

Also, I ran your MQTT daemon and I see you are creating messages with the definition of a sensor. Are you planning to run the script outside HA and use MQTT Discovery?

Right now I'm running everything from custom_components as it's easier without accessing the host OS.

richie256 commented 4 years ago

Hi @llluis ,

Right now I'm running everything from custom_components as it's easier without accessing the host OS.

I would be very much interested about getting your code! even if it is not finished! Do you want to share?

Thanks

llluis commented 4 years ago

Hi @richie256 I'll upload it to github so everybody can use and contribute. Will come back when done.

titilambert commented 4 years ago

@llluis Hello ! Personally, I prefer to reduce the number of custom_components for some reasons (hass start time, maintenance, each update of the component implies a hass restart) so I'm trying to run custom stuff through MQTT. BUT I'm completely open to host this custom component in this repository. If you want, I can add you as contributor of pyhydroquebec, you will be able to commit the component, and review people PR for the component, and then users will be able to download the component from here.

llluis commented 4 years ago

Hey @titilambert, great idea, thanks! I'll send you the code... Reviewing right now.

Agreed with custom stuff, but it's much more user friendly through custom_components. I'll keep this one till the MQTT is done.

Any reason to split the MQTT impl in 2, and hosting in gitlab half of it?

titilambert commented 4 years ago

What do you mean by:

Any reason to split the MQTT impl in 2, and hosting in gitlab half of it?

llluis commented 4 years ago

What do you mean by:

Any reason to split the MQTT impl in 2, and hosting in gitlab half of it?

You have mqtt-hass-base on gitlab and mqtt-daemon (which extends it) here. I didn't understand the separation.

I made a few changes to make it work inside HA: I thought to repackage everything to be able to create a custom_component (remove the blocking loop, for instance).

llluis commented 4 years ago

hydroquebec_custom.zip

There you go. Delete after import.

Normand9999 commented 4 years ago

Hi llluis, I am using your custom component and so far I am able to get both sensors (yesterday_total_consumption and yesterday_average_temperature) but unless I restart HA I don't get updated data every day. Any ideas what is the issue. Thks .

llluis commented 4 years ago

@Normand9999, I fixed 2-3 bugs already since I posted this. I was waiting on @titilambert to publish the code so I could commit the changes. This includes a change in this lib for which I submitted a pull request. There is still one bug I couldn't fix to have it updating everyday without errors, I'm still in the learning curve of HomeAssistant HTTP session. As soon as I get it fixed, I'll share.

llluis commented 4 years ago

For all of you waiting, I published the working version at https://github.com/llluis/home-assistant/tree/master/config/custom_components/hydroquebec

Note that it will pull my pyhydroquebec fork, which contains minor changes to work on HA.

MattL0 commented 4 years ago

@llluis how do you install this and run this on home assistant

ThierryBegin commented 4 years ago

I've been able to make pyhydroquebec work on Version 3.0.0 but now I'm also struggling on understanding on how to make it work through MQTT or directly with Home Assistant

p0pp3t0n commented 4 years ago

So i got this working for home assistant. These are the steps that i did. I'm running Home Assistant 0.108.3 using venv python 3.8 on centos7.

  1. Download the file from @llluis repo. I'm putting them in my .config/homeassistant/hydroquebec It's possible that you might not have that folder. Just create it. wget https://raw.githubusercontent.com/llluis/home-assistant/master/config/custom_components/hydroquebec/sensor.py wget https://raw.githubusercontent.com/llluis/home-assistant/master/config/custom_components/hydroquebec/manifest.json wget https://raw.githubusercontent.com/llluis/home-assistant/master/config/custom_components/hydroquebec/__init__.py

  2. I downloaded the requirements manually. The deps/ is found in my .config/.homeassistant/deps

pip install --target deps/ --no-dependencies https://github.com/llluis/pyhydroquebec/archive/master.zip#pyhydroquebec==3.0.5

  1. Put the configuration in your configuration.yaml. It only has those 4 sensor types. To find your contract number just log in the hydroquebec website and look for it.

sensor:

  1. Verify your configuration and if everything is good restart HA. You should see it in the entities. In my case i didn't use the yesterday_average_temparature. This reflects in the screenshot.

image

image

I hope this helps someone.

Cheers.

QcVictor commented 4 years ago

tks p0pp3t0n, got it working on docker with your explanation

ThierryBegin commented 4 years ago

I'm using hassio so i'm not sure how to get it to work Iget Platform error sensor.hydroquebec - No module named 'pyhydroquebec' most likely because I can't run the pip command... anyone know where I should put it?

QcVictor commented 4 years ago

After rebooting all sensors from hydro quebec are gone ! not sure what happen nothing in the logs about that..

betelz commented 3 years ago

I'm using hassio so i'm not sure how to get it to work Iget Platform error sensor.hydroquebec - No module named 'pyhydroquebec' most likely because I can't run the pip command... anyone know where I should put it?

I'm on the same boat. Running hassio and can't run pip3 install. I also get the same No module named 'pyhydroquebec' error.

lucboudreau commented 3 years ago

This may help some people trying to get Hydro Quebec data back into their HA instance. My solution was to host a docker container with docker-compose. The data is sent to my MQTT server. The sensors are recognized by HA and automatically configured.

Below is the abridged docker-compose configuration I've used.

  pyhydroquebec:
    container_name: pyhydroquebec
    image: registry.gitlab.com/ttblt-hass/pyhydroquebec/mqtt:master
    volumes:
      - /home/user/pyhydroquebec:/etc/pyhydroquebec
    restart: unless-stopped
    environment:
        - MQTT_USERNAME=user
        - MQTT_PASSWORD=password
        - MQTT_HOST=X.X.X.X
        - MQTT_PORT=1883
        - ROOT_TOPIC=homeassistant
        - MQTT_NAME=pyhydroquebec
        - LOG_LEVEL=INFO

The volume mount contains a single file called pyhydroquebec.yaml.

timeout: 30
frequency: 10800
accounts:
- username: your@email.com
  password: password
  contracts:
    - id: 123456789
ioio85 commented 3 years ago

Thank you so much Luc. I have been looking for some instructions for months. This really helped !

For anyone who is interested these are additional details how I did it:

Cheers

roger1233 commented 3 years ago

Merci @lucboudreau

I was not able to go the docker route however, since I use a raspberry pi, and I can't find an arm version of the docker. Is there one?

In the meantime, I used @p0pp3t0n solution (which is deprecated from ha, I know) and it works. Thanks!

roger1233 commented 3 years ago

I'm using hassio so i'm not sure how to get it to work Iget Platform error sensor.hydroquebec - No module named 'pyhydroquebec' most likely because I can't run the pip command... anyone know where I should put it?

Got the same error. It seems HA will run the pip command after restart and will get the module, because of the mention of it in manifest.json... So just ignore and restart. It worked for me. Hope this helps.

betelz commented 3 years ago

Thanks @lucboudreau.

I had never used Docker before. I read and learned. It's always fun to learn new things.

Here's what I've done for those who, like me, are wondering how to use Docker-Compose.

To automate the start-up of my container I have created a systemctl service ref: https://stackoverflow.com/questions/43671482/how-to-run-docker-compose-up-d-at-system-start-up/45193532 To control the service: systemctl start docker-compose-app.service systemctl status docker-compose-app.service systemctl stop docker-compose-app.service

mshamash commented 2 years ago

Thanks for posting this @lucboudreau and @betelz . I managed to get Home Assistant connected with pyhydroquebec docker via MQTT. Any advice on how I can now use the hydroquebec_123456789_yesterday_total_consumption in the Energy tab to monitor grid consumption daily? Or at least get some sort of graph/statistics, since this value updates once a day? Thanks in advance.

betelz commented 2 years ago

I use mini-graph-card (Installed from HACS).

image

Here is the Lovelace YAML I use for this card.

aggregate_func: max
entities:
  - color: yellow
    entity: sensor.hydroquebec_123456789_yesterday_total_consumption
    name: Energie Maison
group_by: date
hour24: true
hours_to_show: 360
name: Energie Maison (hier)
show:
  graph: bar
type: custom:mini-graph-card

I didn't try the Energy Tab yet.

mshamash commented 2 years ago

Thank you @betelz that worked perfectly!

arsenicks commented 2 years ago

I think this may interest some of you guy's: https://github.com/titilambert/pyhydroquebec/issues/64

TL;DR I've created a hass add-on for pyhydroquebec, surely far from perfect but I got everything working for most arch and looking for feedback, so feel free to test and report issue!

https://github.com/arsenicks/pyhydroquebec-hass-addons

petebdeblois commented 2 years ago

@arsenicks at this point, I don't think this repo is maintained. Do you have plan to maybe fork and maintained an image of your own? THere is some interesting PR here that are not reviewed/merged. Like the Hourly data.

arsenicks commented 2 years ago

@petebdeblois Yeah that's what I realised in the last few days. According to my research @titilambert hasn't posted since january 24 here but he's still active on Github as far as I can see(his last PR nov. 5 on other projects).

So to answer your question I have no plan to fork and maintain this repo, my contribution was aiming at using pyhydroquebec and create an easy to use add-on for HASS.

I would be happy to step in if the owner of this repos clearly state he doesn't want to maintain it anymore, but unfortunately I don't think I have the python skills required to maintain and review code.. seeing all those PR lined up, I'm pretty sure there's skilled people here that could step in. I would be happy to help for everything I can if needed..

But again, I think we really need to hear from @titilambert at this time.. One of his last post state he's been off a little bit waiting for HQ to send him test user and password for unit tests. My guess, he's probably dead waiting for HQ according to my experience with them..

TL;DR No plan Like that, will still work on the hass add-on, maybe a custom integration available in HACS in near future. We need to know the state of this project before anything can be done, otherwise we'll fragment the community and it will be more confusing than anything.

Normand9999 commented 2 years ago

Great add-on arsenicks. I was able to get yesterday total consumption and yesterday average temperature using a custom component for the last year (not through MQTT) but with your add-on I have much more entities which is great. Thanks you for sharing the information.

mvonh commented 2 years ago

@arsenicks Hi nice work. I installed and run it. I missed the info about the 2 config files, but once I read it again I got it working. Anyway to get it to play nice with the new energy tracking functionality in Home assistant?

https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics

arsenicks commented 2 years ago

@arsenicks Hi nice work. I installed and run it. I missed the info about the 2 config files, but once I read it again I got it working. Anyway to get it to play nice with the new energy tracking functionality in Home assistant?

https://developers.home-assistant.io/docs/core/entity/sensor/#long-term-statistics

Yes, take a look at this comment: https://github.com/arsenicks/pyhydroquebec-hass-addons/issues/9#issuecomment-990333908

I haven't try because I got my Hilo setup so I don't use the add-on anymore.. So if anyone in the community want to step up fork and maintain it that would be great I could give permission on my repo too. But I know myself, if I don't use it anymore I probably won't put too much effort into that... There's only 24h in a day after all!

mvonh commented 2 years ago

Ok cool, sorry I missed this. Thanks again, have fun with Hilo--how do you like it?

arsenicks commented 2 years ago

It's been great so far. I don't like the light dimmer tho, but the thermostat are great.. The integration into HA has to be rebuilt from scratch following an update on Hilo side the day I got my installation done.. So far the new integration work great with fre bugs but it's fun!