Tuyalocal yaml Configuration

Hi,

I cant seem to get tuyalocal to run though yaml.

If i go though the integration screen and use the GUI i can add my device but i have a lot of devices to add and would much rather use yaml. If I try to add a device though yaml home assistant says my config is valid but once home assistant has restarted I have no switch or any errors as far as i can tell. The sensors I have listed do get added but have a state of “Unavailable”.

What am I doing wrong? Is my config incorrect?

I installed tuyalocal by cloning GitHub - rospogrigio/localtuya: local handling for Tuya devices to my custom custom_components folder.

switch:
  - platform: localtuya
    host: x.x.x.x
    local_key: "xxx"
    device_id: "xxx"
    name: tuya_g4
    friendly_name: tuya_g4
    protocol_version: 3.3
    switches:
      sw01:
        name: tuya_g4
        friendly_name: G4 plug
        id: 1
        current: 18 
        current_consumption: 19 
        voltage: 20 

sensor:
  - platform: template
    sensors:
      tuya_g4_voltage:
        friendly_name: "G4 voltage"
        unit_of_measurement: "V"
        value_template: "{{ states.switch.tuya_g4.attributes.voltage }}"

      tuya_g4_current:
        friendly_name: "G4 current"
        unit_of_measurement: "mA"
        value_template: "{{ states.switch.tuya_g4.attributes.current }}"

      tuya_g4_current_consumption:
        friendly_name: "G4 current consumption"
        unit_of_measurement: "W"
        value_template: "{{ states.switch.tuya_g4.attributes.current_consumption }}"

Your config doesn’t quite look like rospogrigio/localtuya: local handling for Tuya devices (github.com)

You are correct.

I did originally try to use a config like that but kept placing it under a switch node and all examples i found online were more like my above config. Another thing that had me stuck for a while is localtuya and entities node do not accept name as a parameter and instead seem to generate the entity name using the friendly_name.

Below is my working config incase it helps anyone else.

localtuya:
  host: 192.168.1.x
  local_key: "xxx"
  device_id: "xxx"
  protocol_version: "3.3"
  friendly_name: "Device 1"
  entities:
    - platform: switch
      friendly_name: "Plug 1"
      id: 1
      current: 18
      current_consumption: 19
      voltage: 20

sensor:
  - platform: template
    sensors:
      bnetasa_plug1_voltage:
        friendly_name: "Plug1 voltage"
        unit_of_measurement: "V"
        value_template: "{{ states.switch.plug_1.attributes.voltage }}"
      bnetasa_plug1_current:
        friendly_name: "Plug1 current"
        unit_of_measurement: "mA"
        value_template: "{{ states.switch.plug_1.attributes.current }}"
      bnetasa_plug1_current_consumption:
        friendly_name: "Plug1 current consumption"
        unit_of_measurement: "W"
        value_template: "{{ states.switch.plug_1.attributes.current_consumption }}"