Not at all, this has gotten me somewhere, and I am learning as I go.
Updated my last bit of code to have the endif with the curly brackets, and no errors from the code editor, but checking through developer tools, I get this warning
Configuration warnings
Invalid config for ‘file’ from integration ‘sensor’ at configuration.yaml, line 31: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘=’) for dictionary value ‘value_template’, got ‘{% set reading = value.split(“,”)[81] %} {% if reading = '-' %}\n {{states('sensor.River_Height')}}\n{% else %}\n {{ reading }}\n{% endif %}\n’
I indented, as per the link you provided, I think the indent on the { reading } (action bit) is right, but not indenting makes no difference to the warning.
I apologise for being painful.
Yes, I am restarting HA after a change, not just reloading the yaml.
I have now change the reference to the sensor further up in the code (name), so that all references are river_height (lowercase), as I had changed it in the if statement.
And get the same error, with lowercase name now.
Invalid config for ‘file’ from integration ‘sensor’ at configuration.yaml, line 32: invalid template (TemplateSyntaxError: expected token ‘end of statement block’, got ‘=’) for dictionary value ‘value_template’, got ‘{% set reading = value.split(“,”)[81] %} {% if reading = '-' %}\n {{states('sensor.river_height')}}\n{% else %}\n {{ reading }}\n{% endif %}\n’
Progress, I think.
With the ‘==’ in place, a different error. One that to me signifies that it is not handling the '-" and still trying to read it as a int and than a float. I think
Log details (ERROR)
Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:368
Integration: Sensor (documentation, issues)
First occurred: 2:39:48 PM (1 occurrences)
Last logged: 2:39:48 PM
Error while setting up file platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 639, 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 642, in state
numerical_value = float(value)
^^^^^^^^^^^^
ValueError: could not convert string to float: '"-"'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 368, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1282, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 945, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1066, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1003, in __async_calculate_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 951, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 646, in state
raise ValueError(
ValueError: Sensor sensor.river_height has device class 'None', state class 'None' unit 'm' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '"-"' (<class 'str'>)
Thought that maybe if I initialise the value/reading, it would pick up from there. So manually set the ‘-’ in the csv file to ‘0.52’ by copying and pasting a value from another column, and get the same error - but only the float one.
I hope this helps, and thanks for all the help so far.
The column I am after within the csv is E1702, or the data after the 81st comma. But if you get it working for any, then we should be able to adapt.
Looking further, there does seem to be a data api of some sort (well out of my wheelhouse), and some information can be found at