I got a serial port sensor with the following data: {“WaterUse”:10.69}
I don’t get the template correct so that home assistant can understand it.
This is the template I have made:
sensors:
WaterUse:
friendly_name: Water meter
unit_of_measurement: "M3"
value_template: "{{ states('sensor.serial_sensor') | float | round(1) | float (default=0)}}"
Can someone please explain why the data is not interpreted correctly? because I don’t understand.
Because you have not told it to look for json data and what key to look for in that json data. You do this with a value_template.
Like this:
sensor:
- platform: serial
name: Water Meter
serial_port: /dev/ttyUSB1
baudrate: 9600
value_template: "{{ json_value.WaterUse }}"
If you want, you can add an icon and unit_of_measurement using customise as these are not in included in the available options for this sensor (see “serial” link below). Note how the entity id has changed by including a name in the configuration.
This goes under homeassistant: in your configuration.yaml file, see the example in the “customize” link below.
The documents are your best resource. They include the available options for each integration, what type of data each option expects and if they are optional. There are usually a number of examples too.
For a basic understanding of yaml (lists vs dictionaries) this is a good read:
Thanks for all the info. But it still doesn’ t work only I don’t see any error message. So I don’t have a clue what the problem is. i only found state unknown.
Thanks!!!
This seems to work.
Only I don’t understand why home assistant doesn’t understand that this is json.
It looks like a valid json line. Only there is no space after the : but is that required in json?
any suggestions?