Hello i’m using Tuya Local to do local integration with my devices and noticed that my smart plug did not have full integration with the application.
Either I had a device that could be turned on and off or I had a consumption meter but never both now i can use it’s as a HA energy consumption entity and have all thing like in Tuya App.
So based on the existing components i’ve create my own to fullfill my needs.
Hope it helps someone.
I’ve edited the component in “custom_components/tuya_local/devices/smartplugv2_polled_power.yaml” this one already have almost everithing i needed and i can choose this as an onption to my device so it’s easier but you can use what fits best for you.
In my case part of the code come from another components and the switch of “Overcharge cutoff” comes with the wrong ID so maybe some of you face this same issue and to take the correct ID of the swith you just need to go to Tuya IoT plataforma → Clound → API Explorer → Device Controla → put your device ID → submit the request and all properties of the device ll show up, you just need to take the correct ID what you want to control.
name: Energy monitoring smartplug
primary_entity:
entity: switch
class: outlet
dps:
- id: 1
type: boolean
name: switch
- id: 21
type: bitfield
name: factory_test
optional: true
- id: 26
type: integer
name: fault_code
optional: true
secondary_entities:
- entity: switch
name: Overcharge cutoff
category: config
icon: "mdi:battery-charging"
dps:
- id: 39
type: boolean
name: switch
optional: true
mapping:
- dps_val: null
invalid: true
- entity: number
category: config
name: Timer
icon: "mdi:timer"
dps:
- id: 9
type: integer
name: value
unit: min
range:
min: 0
max: 86400
mapping:
- scale: 60
step: 60
- entity: sensor
class: energy
dps:
- id: 17
type: integer
name: sensor
mapping:
- scale: 1000
unit: kWh
class: total_increasing
- id: 21
name: unknown_21
type: integer
- id: 22
name: unknown_22
type: integer
- id: 23
name: unknown_23
type: integer
- id: 24
name: unknown_24
type: integer
- id: 25
name: unknown_25
type: integer
- id: 26
name: unknown_26
type: integer
- entity: sensor
category: diagnostic
class: voltage
dps:
- id: 20
name: sensor
type: integer
class: measurement
force: true
unit: V
mapping:
- scale: 10
- id: 22
type: integer
name: calibration
optional: true
- entity: sensor
category: diagnostic
class: current
dps:
- id: 18
name: sensor
type: integer
class: measurement
force: true
unit: mA
- id: 23
type: integer
name: calibration
optional: true
- entity: sensor
category: diagnostic
class: power
dps:
- id: 19
name: sensor
type: integer
class: measurement
force: true
unit: W
mapping:
- scale: 10
- id: 24
type: integer
name: calibration
optional: true
- entity: select
category: config
name: Initial state
icon: "mdi:toggle-switch"
dps:
- id: 38
type: string
name: option
optional: true
mapping:
- dps_val: "on"
value: "On"
- dps_val: "off"
value: "Off"
- dps_val: memory
value: "Last State"