Local tuya configuration invalid

Hello
I would like to ask for help with the configuration
I use the local Tuya integration and I want to set a sensor for voltage, current and power, but it says that the configuration is invalid

  - platform: template
    sensors:
      Smart_Plug_voltage:
        value_template: >-
          {{ states.switch.smart_plug.attributes.voltage }}
        unit_of_measurement: "V"
      Smart_Plug_current:
        value_template: >-
          {{ states.switch.smart_plug.attributes.current }}
        unit_of_measurement: "mA"
      Smart_Plug_current_consumption:
        value_template: >-
          {{ states.switch.smart_plug.attributes.current_consumption }}
        unit_of_measurement: "W"

Use this:

- platform: template
  sensors:
    Smart_Plug_voltage:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'voltage')|float(0) }}
      unit_of_measurement: 'V'
    Smart_Plug_current:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'current')|float(0) }}
      unit_of_measurement: 'mA'
    Smart_Plug_current_consumption:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'current_consumption')|float(0) }}
      unit_of_measurement: 'W'
1 Like



:c not work

“Invalid slug for [sensor.template]…”

Upper-case/lower-case matters!

- platform: template
  sensors:
    smart_plug_voltage:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'voltage')|float(0) }}
      unit_of_measurement: 'V'
    smart_plug_current:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'current')|float(0) }}
      unit_of_measurement: 'mA'
    smart_plug_current_consumption:
      value_template: >-
        {{ state_attr('switch.smart_plug', 'current_consumption')|float(0) }}
      unit_of_measurement: 'W'
1 Like