Can someone please help me a little with some YAML. I have been trying all day and not getting anywhere!
I have a serial sensor and the following YAML works in configuration.yaml.
sensor:
- platform: serial
serial_port: /dev/ttyUSB0
baudrate: 4800
I now I want to process the data from this serial sensor. It comes as coma delimited text lines like this:
$IIVHW,T,121,M,00.03,N,00.05,K61
$IIDBT,010.5,f,003.2,M,001.7,F12
$IIVWR,008,L,00.0,N,00.0,M,000.0,K41
$IIMTW,020,C3F
$IIHDM,121,M*3E
I want to define different sensors depending on the value of the first field of each line. And then set the state to one of the other fields in the line. Here is pseudo code for what I want to do:
if $IIDBT then
sensor:
name: Water Depth
state: “{{ states(‘sensor.serial_sensor’).split(’,’)[3] | float(default=0) }}”
else if $IIVHW then
sensor:
name: Compass Heading
state: “{{ states(‘sensor.serial_sensor’).split(’,’)[3] | float(default=0) }}”
else if $IIMTW then
sensor:
name: Water Temperature
state: “{{ states(‘sensor.serial_sensor’).split(’,’)[1] | float(default=0) }}”
In the serial help guide of HA there is this example:
template:
sensor:
- name: Temperature
unit_of_measurement: “°C”
state: “{{ states(‘sensor.serial_sensor’).split(’,’)[1] | float(default=0) }}”
- name: Humidity
unit_of_measurement: “%”
state: “{{ states(‘sensor.serial_sensor’).split(’,’)[2] | float(default=0) }}”
But I need the if then else included.
Thanks in advance.