• How to add P1 Energy meter to Synology Home Assistant?
    • Install the package via SynoCommunity
    • SSH via Putty to Synology
      • Login with userid and password
      • Type "sudo -i" to have root access and provide password
      • Type "ls /dev/ttyUSB*" if you receive the message “No such file or directory” perform the following steps:
        • Make a shell script “/usr/local/etc/rc.d/startup.sh”
        • Type cd /usr/local/etc/rc.d/ and then vi startup.sh. And now the VI Script editor opens
        • Press I to go to Insert Mode and add the following code:
        • #!/bin/bash
          insmod /lib/modules/usbserial.ko
          insmod /lib/modules/ftdi_sio.ko
        • Close with :wq (saving and exiting the .sh script
        • On the command line "chmod 755 startup.sh"
        • Type 2x "exit" to quit SSH via Putty and reboot the NAS
    • After the reboot of the NAS please setup a SSH session again (root modus).
      • Type "chmod 666 “/dev/ttyUSB0”" which gives the proper (execute) permissions to the USB0.
    • You can now add the P1 meter to Home Assistant (DSMR)

 

InfluxDB + Grafana

Section 1 - Deploy InfluxDB 2.x in Docker

  • Go to Synology Docker app and in the "Registry" section search for "InfluxDB" and double-click the top entry.

  • Choose the "latest" tag. As the name suggests this will download the latest image, which is currently 2.0.7.

  • Go to the "Image" section of Docker app and double-click the downloaded image to start the Docker deployment.

  • Assign a name to the container (InfluxDB, for instance) and click "Advanced Settings"

  • Select the "Enable auto-restart" checkbox to make sure your container gets back up if it crashes for whatever reason. Click on the "Volume" tab.

  • Click the "Add Folder" button and choose the location on your host filesystem, where InfluxDB will be storing its persistent data (most notably the database). I chose docker/influxdb. Click "Select" button to go back to previous window.

  • On the "Mount path" you now have to point to the container location which will be linked with the location on your filesystem. In this case this is /var/lib/influxdb2 Click on the "Port Settings" tab.

  • Here it's best if you set the "Local Port" section to 8086. This is the default InfluxDB port and all the instructions will refer to it in all the guides. You can set it to almost anything else, but then you'll always have to keep that in mind later. Click on "Environment" tab.

  • This is optional, but highly recommended. Add your timezone in the environment variables, so that you'll have proper timestamps in your database entries. Click "Add" button and in the "variable" field enter TZ and in the "Value" field enter your timezone in format continent/City (you can find a list here

    ). You can now click the "Apply" button.

  • You're back at the initial Docker create window. Click the "Next" button.

  • You have the option of reviewing your settings and then click "Done" when you're ready to start the container.

 

Section 2 - Initial Config of the InfluxDB

  • Wait about a minute for the container to start, then open a web browser and point it to http://10.0.0.11:8086

     (replace with your IP).

  • You'll be greeted with a welcome page, click the "Get Started" button.

  • Here you will create an administrative user and your first (and maybe only) organization and a bucket. I strongly recommend that you do not name the user "admin" or "administrator". Such naming significantly increases risk of successful brute-force attacks, should they ever be attempted.

  • Most likely this will be the only user which you will create, since InfluxDB changes how databases are accessed (we'll come to that later). Organization is a logical unit, mostly useful if you have a valid reason for strict separation of databases (like a service provider with multiple customers). This means that in a home scenario you'll most likely just have one. Bucket is an InfluxDB name for a database.

  • So, choose your username and password. Then also choose an organization name and a bucket (database) name. In my case organization is Home and bucket name is HomeAssistant. Press "Continue" button.

  • On the next screen I chose the "Quick Start" button, since I like that local db metric collection will be setup :-)

 

Section 3 - Setting up access in Influx DB for HomeAssistant and Grafana

  • You're now in the InfluxDB web GUI. At the moment we'll be interested in the "Data" section which is third icon from the top on the left side of the GUI. Click on the "Data" icon.

  • Click on the "Buckets" tab.

  • Here you should be able to see the bucket you have created on the initial screen in the previous section. Note the text saying "Retention: Forever". This means that the data in this bucket will never be deleted. While this may be what you want, it can have big implications for storage consumption, depending how much data your environment generates. I would suggest that you monitor storage consumption increase on a daily basis to determine if this will be an issue for you or not. You can always change the retention, so that data gets dropped after a certain period. Click on the "Tokens" tab.

  • Tokens are (for our purposes) a replacement for user accounts. You should see a token for your username already created. We'll create a couple more for better security and particular purpose. One for HomeAssistant to be able to write to the bucket another for Grafana to be able to read from the bucket. Click on the "Generate Token" menu and select the "Read/Write Token" option.

  • We'll create a write token for HomeAssistant. Assign a name (for instance HomeAssistant - Write). In the "Write" section choose the "HomeAssistant" bucket. Click the "Save" button.

  • We'll repeat the process for Grafana read token. Start the process of generating read/write token and assign a name to it (Grafana - Read). In the "Read" section choose "HomeAssistant" bucket and click on the "Save" button.

  • You should now have three tokens created. One with your username and the two new ones. Together with the fact that the HomeAssistant bucket exists, the InfluxDB is now ready to be used. The last thing to do is to extract the token values, because we'll need them soon.

  • Click on the "HomeAssistant - Write" token (directly on the name) and a window will open where a long string will be shown. Copy that string in a text file somewhere and make a note that it belongs to the HomeAssistant - Write token.

  • Repeat the same thing with "Grafana - Read" token.

 

Section 4 - Configure HomeAssistant to write data to InfluxDB

  • Open HomeAssistant "configuration.yaml" file.

  • Enter the following configuration into it:

influxdb:

api_version: 2

ssl: false

host: 10.0.0.11

port: 8086

token: Your HomeAssistant - Write token

organization: Home

bucket: HomeAssistant

  • Make sure to replace the IP address, token value (the HomeAssistant - Write token) and potentially port, organization and bucket values with what you have setup.

  • Save the "configuration.yaml" file and restart the home assistant. Restart is important, otherwise nothing will happen. With that HomeAssistant configuration should be finished.

 

Section 5 - Verification of HomeAssistant configuration in InfluxDB

  • We'll check if HomeAssistant is properly storing data in our bucket. Go back to the InfluxDB web GUI and click on the fourth icon from the top on the left side, called "Explore".

  • On the new page you should see your bucket name in the lower left section of the screen in the "From" frame. To the right of that should be a "Filter" frame. If you scroll through this, you should see entries that are obviously coming from HomeAssistant. They will be different, depending on what your environment is, but it should be obvious that HomeAssistant is their source. In my case I've got several temperature sensors setup in HomeAssistant. I scroll down, to the bottom of the "Filter" frame until I see the "°C" entry. I select that and a new "Filter" frame opens. Here I select the "value" entry.

  • If you wish, you could continue and select specific sensors or just decide that this is sufficient for the test. If you do, then click on the "Submit" button on the extreme right side of the screen.

  • On top of the screen a graph should be generated which will display all temperatures that HomeAssistant is logging. Entries will be limited, since they will start from the moment that you have added HomeAssistant->InfluxDB config into HomeAssistant. However if there are entries, then you have just verified that your configuration is valid and you're doing OK so far.

 

Section 6 - Deploy Grafana in Docker

  • Go back to Synology Docker and open the "Registry" section again. Search for "Grafana" and double-click on the top entry.

  • Choose the "Latest" tag and click on the "Select" button.

  • Go to the "Image" section of the Docker app and double-click the downloaded Grafana image.

  • Assign a name to the container (Grafana, for instance) and click "Advanced Settings"

  • Select the "Enable auto-restart" checkbox. Click on the "Volume" tab.

  • Click the "Add Folder" button and choose the location on your host filesystem, where Grafana will be storing its persistent data. I chose docker/Grafana. Click "Select" button to go back to previous window.

  • On the "Mount path" you now have to point to the container location which will be linked with the location on your filesystem. In this case this is /var/lib/grafana Click on the "Port Settings" tab.

  • Grafana "Local Port" defaults to 3000. Input this value or select your own. Click on "Environment" tab.

  • Like before, set your timezone. Click "Add" button and in the "variable" field enter TZ and in the "Value" field enter your timezone in format continent/City. You can now click the "Apply" button.

  • You're back at the initial Docker create window. Click the "Next" button.

  • You have the option of reviewing your settings and then click "Done" when you're ready to start the container.

 

Section 7 - Initial config of Grafana

  • Wait about a minute for the container to start, then open a web browser and point it to http://10.0.0.11:3000

     (replace with your IP).

  • Login with default username and password of admin and admin

  • You will be prompted to set a new password. Do so and continue.

  • With this Grafana is ready to be connected to InfluxDB so that you can start visualizing the data.

 

Section 8 - Configure Grafana to retrieve data from InfluxDB

  • On the left side choose the seventh icon from the top. The cog icon saying "Configuration".

  • Here we will point Grafana towards the bucket on the InfluxDB server. Click on the "Add data source" button.

  • On the next screen choose the "InfluxDB" from the list of databases.

  • In this window we'll set connection and display parameters for communication between Grafana and InfluxDB.

  • In "Name" field enter a name that makes sense. I suggest "HomeAssistant". This is cosmetic but it helps later especially if you'll have multiple databases from which to choose.

  • Under "Query Language" drop-down choose "Flux". This is a new Query language and may be slightly more complicated but I haven't found a good way to connect to InfluxDB 2.x with IfluxQL. And I'm betting that Flux will be default going forward, so let's bite the bullet now :-)

  • In "HTTP" section under "URL" enter address and port of the InfluxDB container. In my case this is http://10.0.0.11:8086

  • In "Auth" section turn off the "Basic auth" option.

  • In "InfluxDB Details" section under "Organization" enter the one you defined in InfluxDB. In my case it's Home.

  • In "Token" field copy-paste the value of the "Grafana - Read" token, that you saved at the end of Section 3.

  • In "Default Bucket" field enter name of the bucket you created in InfluxDB. In my case it's HomeAssistant.

  • Click the "Save & test" button. If you get a green check-mark, you did good.

  • Your Grafana instance is now configured to retrieve and display data from InfluxDB.

 

Section 9 - Creating first graph in Grafana

  • We now want to actually display all that data. In Grafana web GUI, click on the third icon from the top. The one with the + sign, named "Create".

  • We will create a test panel. So click on the "Add an empty panel" choice.

  • This is the challenging part. In the past we could simply select entries and have a graph show up. Now we have to use the Flux query language which expects us to type things in. Well, thankfully there's a trick that we can use. And it starts by going back to the InfluxDB web GUI.

  • Open the InfluxDB web GUI in a new tab and login.

  • On the left side choose the "Explore" icon.

  • Like in section 5, where we verified operation, we'll create a query. Only that now, this will be a query that we would actually want to display in Grafana. Here I cannot give you detailed steps as the query selection depends on what you want. So I'll let you build it yourself by clicking through filters in the bottom half of the window. When you're done click the "Submit" button on the right.

  • Once your query is built and you see the results in the upper part of the screen, locate and click the "Script Editor" button that's just to the left of the "Submit" button, that you clicked one step before.

  • When you do this query panels will disappear and be replaced with a Flux query. Select the whole query and copy it into clipboard.

  • Switch back to the Grafana tab in your browser.

  • Paste the query into the query "A" field in the bottom half of the "New dashboard / Edit panel" window which should still be open.

  • Under the query field locate and click the "Sample Query" button.

  • If things are good, you should now see in the top part of the window the graph representing contents of your query.

  • All that is left to do is to tweak this a bit, by assigning a title to the panel and saving the dashboard by clicking the "Save" button on the top-right corner.

  • You will have to assign a name for the dashboard, click "Save" again and you're done.

 

This is where I leave you. First panel in the first dashboard is finished. Now you can tweak things to your liking, create additional panels, queries and whatnot.