I can't save data from the form to a file

Hello everyone,
I needed to enter digital data into a form, and from this form write this data to a file. According to the documentation, I found that this is possible and wrote a small automation:

alias: "H1 - test_test_test"
trigger:
  - platform: state
    entity_id: input_number.test_1
  - platform: state
    entity_id: input_number.test_2
  - platform: state
    entity_id: input_number.test_3
condition: []
action:
  - service: shell_command.append_utility_reading
mode: single

I sketched a simple card on the dashboard:

type: entities
entities:
  - entity: input_number.test_1
    name: Test 1
  - entity: input_number.test_2
    name: Test 2
  - entity: input_number.test_3
    name: Test 3
title: N Test test tesT

in the configuration file for shell_command, I added:

append_utility_reading: |
  echo "{{ now().strftime('%Y-%m-%d %H:%M:%S') }},{{ states('input_number.test_1') }},{{ states('input_number.test_2') }},{{ states('input_number.test_3') }}" >> "/config/share/utility_readings.csv"append_utility_reading: "echo \"{{ timestamp }},{{ hw }},{{ cw }},{{ ed }}\" >> /config/share/utility_readings.csv"

separately, the sensor also prescribed:

sensor:
  - platform: local_file
    name: "utility_readings_file"
    file_path: /config/share/utility_readings.csv

there are no errors in the system, and no data is written to the file… If I’m doing something wrong, help me find a solution so that the data is written to a file.

Is that an error in the post, or is it really what you have as the shell command?

1 Like

Why not just use the File integration?

But note that the error Chris asked about above includes undefined variables, which would cause it to fail:

..."{{ timestamp }},{{ hw }},{{ cw }},{{ ed }}\"...

If you want to use variables like that in the command, you need to pass their value in the action data.

alias: "H1 - test_test_test"
triggers:
  - trigger: state
    entity_id: 
      - input_number.test_1
      - input_number.test_2
      - input_number.test_3
conditions: []
actions:
  - action: shell_command.append_utility_reading
    data:
      timestamp: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
      hw: "{{ states('input_number.test_1') }}"
      cw: "{{ states('input_number.test_2') }}"
      ed: "{{ states('input_number.test_3') }}"
mode: parallel

In one of the options it was exactly like that :lying_face:, I tried to create and place a file in other directories. Through the ssh terminal, I changed the chmod on the file and on the directory. Realizing that I was walking in circles and there was no result, I wrote here.

I started my search for a solution with this integration, but either I didn’t figure it out, or it didn’t fit my needs… If you can provide any example related to a dashboard card and recording information from it into a file using the integration you specified, I would appreciate it.

The notification option of the integration basically does what you are trying to do with your shell command, the frontend input is something separate…

Using the same Input Number helpers you already have, once you set up the integration, the automation would be something like:

alias: "H1 - test_test_test"
triggers:
  - trigger: state
    entity_id: 
      - input_number.test_1
      - input_number.test_2
      - input_number.test_3
conditions: []
actions:
  - action: notify.send_message
    data:
      message: "{{ states('input_number.test_1') }},{{ states('input_number.test_2') }},{{ states('input_number.test_3') }}"
    target:
      entity_id: notify.file_utility_reading
mode: parallel

Though, a better option might be to use a Script that you fire manually instead of an Automation that fires for each input entity. You would add the script entity to your card so you can easily run it after you update the last value. That would keep your file from being 2/3 useless data.


Regarding the “dashboard card” aspect… If you aren’t happy with the layout/input functionality of the Entities card, you might want to take a look at the Custom Text Input Row.