Sensor data published on WordPress site

I am using a Raspberry Pi3/HA setup to - among others - keeping an eye on temperature and humidity conditions. Secure remote access to HA is possible, however I wanted to have data easily accessible and nicely displayed on a WordPress site. I ended up building a WordPress plugin that uses data HA is pushing to present both values and graphs.
The WordPress plugin itself is pretty straight forward in terms of use with generation of secret key for transfering data and short codes for displaying.
In order to get HA to send sensor data, the following (not so comfy ;-)) manual steps are necessary:

  1. adding access data to the WordPress site (URL, key) in secrect.yaml
  2. adding a fee lines to configuration.yaml
  3. automation for pushing data


Backend WordPress


Temperature and humidity


Sensor battery state

2 Likes

Hello archienorway,

This is a bit interesting to me. I might have an application.
However if I wanted to do this, there are not enough details here to help me.
Do you use webhooks or something to pass the data around? My WordPress is remote rented from a big company.
Congratulations on getting it working though.

1 Like

Hi!
Home Assistant pushes data every 5 minutes to WordPress.
Data is stored in the Wordpress database for 90 days (by default).
For the transfer, I use both a secret key and an application password.

OK, but doesn’t help me re-create it at all.

Apologies for the lack of detail. I got the impression you wondered about the bigger picture.
After activiating the WordPress plugin (which is in its beta stage), configuration.yaml has to edited in order to allow an automation to submit data to WordPress. URL and secret have to be defined in secrets.yaml.

rest_command:
  ha_push_point:
    url: !secret ha_wp_url
    method: POST
    content_type: "application/json"
    timeout: 10
    verify_ssl: true
    headers:
      X-HA-Secret: !secret ha_wp_secret
    payload: >
      {{
        {
          "sensor": sensor,
          "value": (value | float(default=none)),
          "ts": now().isoformat()
        } | tojson
      }}

rest_command:
  ha_push_batch:
    url: !secret ha_wp_url
    method: POST
    content_type: "application/json"
    timeout: 10
    verify_ssl: true
    headers:
      X-HA-Secret: !secret ha_wp_secret
    payload: >
      {% set ts = now().isoformat() %}
      {{
        {
          "points": [
            {"sensor":"sensor.XXX_temperature",               "value": states('sensor.XXX_temperature')              | float(default=none), "ts": ts},
            {"sensor":"sensor.XXX_humidity",                  "value": states('sensor.maler_XXXt_humidity')                 | float(default=none), "ts": ts},
            {"sensor":"sensor.XXX_battery",                   "value": states('sensor.maler_XXX_battery')                  | float(default=none), "ts": ts}
          ]
        } | tojson
      }}
 
1 Like