Hi
I want to write data to a file and then use the information to configure some functions after a restart.
In this example is it the zone in which my automower “zlatan” is working.
I use a file sensor to read information from a file.
sensor:
- platform: file
name: ZZ zone
file_path: logs/zlatan_zone_selected_zone.json
value_template: '{{ value_json.zone }}'
This sensor needs the data on a json format as in the sample below.
{"zone": "front"}
The problem is to write the data to the file with correct format. I use a file notification and it is working fine as long as the value is hardcoded.
notify:
- platform: file
name: log_zz_state
filename: logs/zlatan_zone_selected_zone.json
timestamp: false
automation:
- alias: "automation_zlatan_zone_front"
- service: notify.log_zz_state
data:
message: "{\"zone\": \"front\"}"
But I should not need to hardcode the value. The zones are listed in an input_select list and I want to dynamically write the value to the file, but it will not work.
automation:
- alias: "automation_zlatan_zone_front"
- service: notify.log_zz_state
data:
message: "{\"zone\": \"{{ states('input_select.select_zlatan_zones') }}\"}"
I can write a state value to a file, but when I add the correct format with brackets, double quotation marks and colon then the notification will crash. Why?
What am I doing wrong?
//Mats