Cheap ceiling fan integration with local tuya

Just a post to share that I got a cheap ceiling fan working locally with home assistant and the local tuya addon.

Here’s the fan: Barnet 44 inch WiFi Smart Ceiling Fan with LED Light Flush Mounted

Here’s the custom integration I used: GitHub - rospogrigio/localtuya: local handling for Tuya devices

The hardest part was finding the id and secret key for the device (explained on their github page). It took a long time, but it’s possible.

Next was the addition to the configuration.yaml to get the light to work properly:

light:
  - platform: template
    lights:
      office_light_1:
        unique_id: "office_light_combined"
        friendly_name: "Office Light"
        value_template: "{{ states('light.light1') or states('light.light2') }}"
        level_template: "{{ state_attr('light.light1', 'brightness')|d(0,true)|int }}"
        turn_on:
          action: light.turn_on
          entity_id: light.light1, light.light2
        turn_off:
          action: light.turn_off
          entity_id: light.light1, light.light2
        set_level:
          action: light.turn_on
          entity_id: light.light1
          data:
            brightness: "{{ brightness }}"

Configuring the entities in the local tuya integration is as follows.
Entity 1: Fan
Primary ID = 1
See screenshot for additional configuration

Entity 2: Light 1
Primary ID = 101
See screenshot for additional configuration

Entity 3: Light 2
primary ID = 9
See screenshot for additional configuration