Sensor transmits multiple time points: How to ingest into HA?

Hello,

I’m using a pimoroni enviro urban sensor over MQTT (see Mosquitto - no data seen in logs (but can log in) - #2 by bjohas, How to add Pimoroni Enviro/Weather sensors - #5 by bjohas).

The sensor is battery powered and transmits the MQTT message over WiFi. The sensor takes readings every 15 mins; however, to save battery (i.e., not connect to WiFi too often), the sensor is set up to transmit the data only every 10 readings.

When the sensor connects via MQTT, the message (when simplified) looks like this:

[
  {
    "payload": {
      "readings": {
        "temperature": 19.1
      },
      "timestamp": "2023-01-31T08:30:09Z"
    },
    "time": "2023-01-31T10:45:25.066912+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.14
      },
      "timestamp": "2023-01-31T08:45:09Z"
    },
    "time": "2023-01-31T10:45:25.387570+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.24,
      },
      "timestamp": "2023-01-31T09:00:09Z"
    },
    "time": "2023-01-31T10:45:25.905377+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.36
      },
      "timestamp": "2023-01-31T09:15:09Z"
    },
    "time": "2023-01-31T10:45:26.424806+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.43
      },
      "timestamp": "2023-01-31T09:30:09Z"
    },
    "time": "2023-01-31T10:45:27.008638+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.45
      },
      "timestamp": "2023-01-31T09:45:09Z"
    },
    "time": "2023-01-31T10:45:27.477199+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.48
      },
      "timestamp": "2023-01-31T10:00:09Z"
    },
    "time": "2023-01-31T10:45:27.997179+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.48
      },
      "timestamp": "2023-01-31T10:15:09Z"
    },
    "time": "2023-01-31T10:45:28.551812+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.54
      },
      "timestamp": "2023-01-31T10:30:09Z"
    },
    "time": "2023-01-31T10:45:29.037363+00:00",
  },
  {
    "payload": {
      "readings": {
        "temperature": 19.61
      },
      "timestamp": "2023-01-31T10:45:09Z"
    },
    "time": "2023-01-31T10:45:29.570528+00:00",
  }
]

You can see that there’s a “timestamp” as part of the reading (which is the time of the measurement) and then a “time” which is when the data was received.

HA uses the “time” for all readings (i.e., I see an entry every 2.5 hours) rather than the “timestamp”. How do I get it to use the timestamp instead of time?

My sensor definition is:

sensor:
  - name: "Indoor Temperature (u01)"
    state_topic: "enviro/enviro-u01"
    value_template: "{{ value_json.readings.temperature }}"
    unit_of_measurement: "°C"
    state_class: "measurement"
    unique_id: "sensor.enviro_u01.temp"

I’m looking for a way to add {{ value_json.timestamp }} into this? E.g., something like

    timestamp: {{ value_json.timestamp }}

? (However, I should add, that have tried both ‘time’ and ‘timestamp’ and it doesn’t seem to work.)

(Also, of course I could set the pimoroni enviro to send the data at every measurement… but this would mean higher battery consumption.)

1 Like

Did you ever get anywhere with this?
I’ve just bought the enviro weather, and didn’t realise this would be a thing.

Hi @ryamoo - unfortunately I never found a solution for this. Did you investigate and get anywhere with it?

I’ve just got the indoor and urban and have the same issue. Wish I’d known before I bought. Seems in theory can use node-red to fiddle with the feed but not got it working. I’m trying my luck here https://community.home-assistant.io/t/how-to-add-pimoroni-enviro-weather-sensors/449510/10 but if a solution is know please let me know.

I’d still be interested in this too! (OP)