So I have this kind of working, although I am getting errors in HA Logs.
I am playing with two ways of importing it
- platform: rest
resource: https://www.data.brisbane.qld.gov.au/data/api/3/action/datastore_search?resource_id=78c37b45-ecb5-4a99-86b2-f7a514f0f447&fields=E1702,_id&limit=1&sort=_id%20desc
method: GET
name: riverheight_pineapple_st
value_template: "{{ value_json.result.records[0].E1702 }}"
scan_interval: 300
unit_of_measurement: "m"
- platform: rest
resource: https://www.data.brisbane.qld.gov.au/data/api/3/action/datastore_search?resource_id=78c37b45-ecb5-4a99-86b2-f7a514f0f447&fields=E1702,_id&limit=1&sort=_id%20desc
method: GET
name: riverheight_pineapple_st_2
value_template: >
{{ (this|default({'state':0})).state if value_json.result.records[0].E1702 == '-' else value_json.result.records[0].E1702 }}
scan_interval: 300
unit_of_measurement: "m"
and then using a template to try and prevent the value updating on a bad read.
template:
- trigger:
- platform: state
entity_id: sensor.riverheight_pineapple_st
not_to:
- unknown
- unavailable
- trigger:
- platform: state
entity_id: sensor.riverheight_pineapple_st_2
not_to:
- unknown
- unavailable
- "0"
Logs when the value is “-” for the first sensor.
Logger: homeassistant.helpers.entity
Source: helpers/entity.py:945
First occurred: March 26, 2024 at 8:21:49 AM (612 occurrences)
Last logged: 7:06:49 AM
Update for sensor.riverheight_pineapple_st fails
Update for sensor.riverheight_pineapple_st_exp2 fails
Update for sensor.riverheight_pineapple_st_exp fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 663, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '-'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 666, in state
numerical_value = float(value)
^^^^^^^^^^^^
ValueError: could not convert string to float: '-'
The above exception was the direct cause of the following exception:
But for the second sensor, it still drops to zero when the reading is “-”, even with the template.
So even though the first sensor (and others I am experimenting with) are creating errors in the log files, they are at least preventing a new/false reading, and keeps the old good value.
It is raining quiet heavily at the moment, for the last few days, so I actually have some data…
Anyone have thoughts on why my template with the “0” in the not_to doesn’t work?