Hello, I am trying to read some sensor values of my Arduino with serial communication. To do this I used the example with the Json given here: https://www.home-assistant.io/integrations/serial/
The data seems to be coming in fine:
To assign the data to a sensor I tried the following:
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
baudrate: 9600
- platform: template
sensors:
my_pressure_sensor:
friendly_name: Pressure
unit_of_measurement: "mbar"
value_template: "{{ value_json.norm }}"'
When I add the sensor to my dashboard is says its unavailable. I found some similar post but can’t quite figure it out.
VDRainer
(🍻)
December 27, 2020, 3:48pm
2
You need to use the state of your serial sensor in the value_template.
value_template: "{{ states('sensor.serial_sensor').norm }}"
Take a look in Dev tools/states for the entity_id.
You can play with the template in Dev tools/templates.
2 Likes
I have been playing with the template a bit
When I use :
value_template: "{{ states('sensor.serial_sensor') }}"
I get the following result:
value_template: "{"norm":1000.11,"hg":0.59,"temp":22.394,"alarmOn":0,"status":1,"counter":19}"
when I add any of the dot entity_id I get :
value_template: ""
I don’t understand why it does not show me the value
VDRainer
(🍻)
December 27, 2020, 6:07pm
4
Please post a screenshot of the result if you use:
{{ states('sensor.serial_sensor') }}
VDRainer
(🍻)
December 27, 2020, 6:34pm
6
Hmm, i waited for the ‘Result type:’ like in my picture, but it looks like a string.
What version af HA are you running?
Another aproach:
The serial sensor has a value_template option built in.
What about:
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
baudrate: 9600
value_template: "{{ value_json.norm }}"
without an extra template sensor?
I am running version 0.115.6 the result type doesn’t show up.
The value template within the serial sensor works. However, I don’t know how I can extract multiple values this way.
VDRainer
(🍻)
December 27, 2020, 7:02pm
8
I don’t know if it’s possible to create multiple serial sensors that way.
The template sensors should be possible by splitting the returned string from the serial sensor (without the value_template).
What does
{{ states('sensor.serial_sensor').split(',')[0].split(':')[1] }}
in the template tool?
Thank you very much for your help, this method works!