Platform file and automation

Hi everyone, I’m currently extracting a value from a JSON of my inverter with the following code

 sensor:
   - platform: file
     name: SoC
     file_path: /config/details.txt
     value_template: "{{ value_json.paramCategoryList[5].fieldList[4].value | float(default=0) }}"
     unit_of_measurement: "%"

what I get is a “sensor.soc” of a percentage value, but the automation does not recognize the value, for example when the number is greater than 50 the automation does not start.
Then, “file” does not allow you to assign classes to the identity
How can I convert “file” to a battery class sensor? Thank you

1 Like

Please format code correctly for the forum: see here.

Please post the correctly-formatted code for your automation and explain what happens versus what you want to happen.

If you’re using a Numeric State trigger, that only triggers when the value crosses the threshold from below the value to above it.

To get a battery class sensor when the file sensor doesn’t accept device_class, you’ll have to duplicate it with a template sensor. You can create this in the UI under Helpers. Use a state template of:

{{ states('sensor.soc') }}