Writing sensor value to a file / time based

Hello,

since some years I’ve used a time based automation to write a sensor value to a file. Since notify has change and since the latest update this automation does not work anymore.
I was not able to find a new solution to make it working again. I’m using the exported data to display it on my mobile phone (using a http call).

alias: Sensor value to file
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition: []
action:
  - action: notify.send_message
    data: {}
target:
  entity_id: notify.writefile1
data:
  message: >-
    {{now().strftime("%d.%m.%Y;%H:%M:%S")}};{{ states.sensor.wohnzimmer.state |
    round(1) }};  {{ states.sensor.wohnzimmer_2.state | round(1) }}; {{
    states.sensor.aussensensor.state | round(1)}};  {{
    states.sensor.aussensensor_2.state | round(1) }}
mode: single

This is the error message:

The automation "Sensor value to file" (automation.sensor_value_to_file) is not active because the configuration has errors.

Error:extra keys not allowed @ data['data']. Got {'message': '{{now().strftime("%d.%m.%Y;%H:%M:%S")}};{{ states.sensor.wohnzimmer.state | round(1) }}; {{ states.sensor.wohnzimmer_2.state | round(1) }}; {{ states.sensor.aussensensor.state | round(1)}}; {{ states.sensor.aussensensor_2.state | round(1) }}'} extra keys not allowed @ data['target']. Got {'entity_id': 'notify.writefile1'}.

To fix this error, edit the automation to correct it, then save and reload the automation configuration.

Thx!

I’d try to replace the syntax

{{ states.sensor.wohnzimmer.state | round(1) }}

to

{{ states('sensor.wohnzimmer') | float(0) | round(1) }}

Thanks, but this has no effect on the error message.

Have you tried to debug it in the Developer Tool - Template tab?
Add in each sensor separately and see when it starts throwing an error.

I assume you made the same change for all sensors.

It looks like there’s also something wrong with the indentations - here’s a sample of an action that works fine for me:

action:
  - metadata: {}
    data:
      message: >
        {{ now().strftime('%d/%m/%Y') }}
    target:
      entity_id: notify.file_name
    enabled: true
    action: notify.send_message

Test done for the sensors without any error. As these are in place since a long time, I don’t expect to have an issue here. It’s more the new notify functionality and the sheduling which behave different since the last update.
Unfortunately the error message of the automation is not precise enough (for me) to identify the root cause.

The error message is precise.
It tells you that data is not a valid key, which it isn’t at that position.
As stated before you have indentation errors, and that is what the error message says also.

I would guess:

action:
  - action: notify.send_message
    target:
      entity_id: notify.writefile1
    data:
      message: >-
 
         {{now().strftime("%d.%m.%Y;%H:%M:%S")}};{{ states.sensor.wohnzimmer.state |
         round(1) }};  {{ states.sensor.wohnzimmer_2.state | round(1) }}; {{
         states.sensor.aussensensor.state | round(1)}};  {{
         states.sensor.aussensensor_2.state | round(1) }}
mode: single

And keep in mind that states.sensor.aussensensor_2.state is a very old way of writing.
You should convert it to states()

After some more checks even with the new notify action, the error did not disappear. Even a simple “Hello world” message does not show up in my file. The error does not come from my states entities. Even with the new format and good indentations it was not working.

But I found a better solution to transfer the entity values to my mobile phone (this was the basic purpose of this logfile): I’ve switched to Tasker and I’m now using an api call to fetch the entity states.