Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95377

Help with value_template for serial port data

$
0
0

@kenm wrote:

I’m trying to figure out how to parse data from a serial port into individual sensors. I’m familiar with Django templating but not so much with Jinja2.

The data is coming from a Midon Design TEMP05 1-wire data logger in the following format:

Sensor #01[E40008001E1A0710]=64.16F

Here’s the configuration.yaml for the serial sensor and a template sensor:

sensor:
  # TEMP05 1-Wire Data Logger 
  - platform: serial
    serial_port: /dev/ttyUSB0
    name: TEMP05

  - platform: template
    sensors:
      computer_room_temperature:
        friendly_name: Computer Room Temperature
        unit_of_measurement: "°F"
        # Sensor #01[E40008001E1A0710]=64.16F
        value_template: >-
          {% if states('sensor.temp05').startswith('Sensor #01') %}
            {{ states('sensor.temp05').split('=')[1].strip('F') }}        
          {% endif %}

I get the following error when checking the configuration:

Error loading /config/configuration.yaml: while scanning for the next token
found character '%' that cannot start any token
  in "/config/configuration.yaml", line 50, column 12

I’m hoping it’s something glaring for those familiar with sensor templating.

EDIT: There might be a clue when looking at the code highlighting. Is it the “#” in the .startswith string that’s causing me grief?

Thanks in advance for any assistance.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95377

Trending Articles