#Reading csv file

1 messages · Page 1 of 1 (latest)

north relic
#

I have a file, fperdas.csv, in /config
Got 3 columns: date , hour and value (value is what i want)
This is what i got:

  - platform: command_line
    name: "Fator de Perdas"
    command: "tail -n +2 /config/fperdas.csv"  # Lê o ficheiro ignorando a primeira linha
    scan_interval: 60  # Atualiza a cada minuto
    command_timeout: 10
    value_template: >-
      {% set csv = value.split('\n') %}
      {% set hoje = now().strftime('%Y-%m-%d') %}
      {% set hora = now().strftime('%H:%M') %}
      {% for linha in csv if linha.startswith(hoje) %}
        {% set dados = linha.split(';') %}
        {% if dados[1].split('-')[0] == hora %}
          {{ dados[2] | replace(',', '.') | float }}
        {% endif %}
      {% endfor %}```

The sensor doesnt even show up. What Im doing wrong?
wicked skiff
#

any logs? probably going over character limit if i had to guess. states have a 255 max character limit. attributes are unlimited

#

your yaml is also wrong, should be

  - sensor:
      name:
      command:``` etc
#

take a look at the docs, make sure you have everything formatted right. theres an example sensor platform you can reference toohttps://www.home-assistant.io/integrations/command_line/

Home Assistant

Instructions on how to integrate the command line utility within Home Assistant.

halcyon fulcrum
#

The first line of the template has a capital ‘S’ in value.Split('\n'). It needs to be lowercase

#

And a space too. Maybe just an error made when copying the code?

north relic
north relic
north relic
halcyon fulcrum
#

You don’t mention what your HA installation method is. That will impact what path you need to specify

#

You might find this guide helpful, particularly the section “testing your command”

https://community.home-assistant.io/t/sshing-from-a-command-line-sensor-or-shell-command/258731