mishaVee
(michael)
March 13, 2020, 6:34am
1
Hey all,
Feeling a little confused reading through the serial documentation help:
and
Basically I am using an Arduino to handle all of my sensors, utilising the arduinoJson.h library to output my variables and values over to my Raspberry Pi 4. which is working fine and I get the following:
{
"Temperature": 23.297,
"pH": 0,
"DisolvedOxygen": 6.35
}
Then I added to my configuration.yaml file
sensor:
- platform: serial
serial_port: /dev/ttyACM0
baudrate: 9600
- platform: template
sensors:
Temperature_sensor:
friendly_name: Temperature
unit_of_measurement: "°C"
value_template: "{{ states('sensor.serial_sensor').split(',')[1] | float }}"
pH_sensor:
friendly_name: pH
value_template: "{{ states('sensor.serial_sensor').split(',')[3] | float }}"
DO_sensor:
friendly_name: DO
unit_of_measurement: "mg/L"
value_template: "{{ states('sensor.serial_sensor').split(',')[5] | float }}"
From my understanding,i have set it so each sensor looks at the value in position 1, 3 and 5 of the string? still getting my head around HA
mishaVee
(michael)
March 15, 2020, 2:01am
2
Okay so just to confirm when i look at the serial port i have set up i get the following:
So its getting the data⌠Iâm just not getting how to break it down. i also tried the follwoing two different options
sensor:
- platform: serial
serial_port: /dev/ttyACM0
baudrate: 9600
name: Arduino
- platform: template
sensors:
temperature_sensor:
friendly_name: Temperature
unit_of_measurement: "°C"
value_template: â{{ float(sensor.value_json.Temperature) }}â
- platform: template
sensors:
weatherstation_temperature:
friendly_name: 'Outside temperature'
unit_of_measurement: '°C'
value_template: "{{ float(states.sensor.Arduino.state.split(':')[3]) }}"
Looks like theyâre different attributes, which youâd be able to do with something like this:
- platform: template
sensors:
temperature_sensor:
friendly_name: "Temperature"
unit_of_measurement: "°C"
value_template: "{{ state_attr('sensor.serial_sensor', 'Temperature') }}"
You can check if this is the right formatting in the âDeveloper Tools > Templateâ section of HA. If it is, youâll get â21â as the value.
You can also have a maximum of one instance of the following:
- platform: template
sensors:
Every sensor you template will go underneath that one configuration so:
- platform: template
sensors:
sensor1:
*details*
sensor2:
*details*
Just remember to check all the value templates you make for sensors in your Developer section to make sure you get the right data.
1 Like
nickrout
(Nick Rout)
March 15, 2020, 5:52am
4
This is not going to work without telling it what sensor to evaluate.
finity
March 15, 2020, 6:12am
5
I donât believe those are attributes. Iâm pretty sure that is the state.
So to pull data out of that state you would need to use the following templates:
{{ states.sensor.serial_sensor.state['pH'] }}
{{ states.sensor.serial_sensor.state['Temperature'] }}
{{ states.sensor.serial_sensor.state['DisolvedOxygen'] }}
itâs hard to test it since I donât have that exact sensor but I tested it in the template editor by creating a variable with your provided info and it worked:
mishaVee
(michael)
March 15, 2020, 9:13am
6
@icaman004 and @finity thank you so much for your explanation/time. I can now stop banging my head up against the wall! Also, I couldnât wrap my head around the dev template tool until now, so big thanks again, guys!!
so for anyone else having issues in the future, I know I struggled to find a solved answer for this in the threads, it was super particular about the formatting, this is what I ended up using to get it to work:
sensor:
- platform: serial
serial_port: /dev/ttyACM0
baudrate: 9600
- platform: template
sensors:
temperature_sensor:
friendly_name: "Temperature"
unit_of_measurement: "°C"
value_template: "{{ state_attr('sensor.serial_sensor', 'Temperature') }}"
ph_sensor:
friendly_name: "pH"
unit_of_measurement: "pH"
value_template: "{{ state_attr('sensor.serial_sensor', 'pH') }}"
do_sensor:
friendly_name: "DO"
unit_of_measurement: "mg/L"
value_template: "{{ state_attr('sensor.serial_sensor', 'DisolvedOxygen') }}"