make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.2k stars 489 forks source link

Support for TH213 Wifi Thermostat #41

Closed ed-holland closed 2 years ago

ed-holland commented 2 years ago

The TH213 is used to control the electric floor heating. image

Using the localtuya integration i was able to get all the parameters (although i do not understand them all. It can be made to work, but it is cumbursome.

Using this integration i was proposed the "andersson_gsh_heater" which visualizes some of the values.

This is what i currently know: image

How easy can a new device be added?

ed-holland commented 2 years ago

I've created a fork and am working on a device file.

make-all commented 2 years ago

For 105, is it really another switch, or is it just an indicator of the heating state? 12 or 110 should be the preset_mode (Home/Away/Smart/Sleep)

ed-holland commented 2 years ago

Indeed 4 is the preset. 105 is when heater is really switched on. I've noticed that current_temperature is alway defined. Will create a value based on ext/int sensor using 102.

The others did not change whatever i changed in the app.

ed-holland commented 2 years ago

I'm struggling with the current_temperature. This is a virtual attribute (no ID on the device) but should provide an attribute in HA which contains the value of either id=3 or id=101 depending on the value of id=102.

Can anybody help? Is this possible at all?

make-all commented 2 years ago

I would just return the internal temperature as current_temperature, as that should be always available, and return the external temperature under a different name. Complex logic is difficult to implement in a declarative config file.

ed-holland commented 2 years ago

I've used this device configuration

name: AWOW TH213 Thermostat for electrical floor heating
legacy_type: th213_thermostat
primary_entity:
  entity: climate
  dps:
    - id: 1
      name: hvac_mode
      type: boolean
      mapping:
        - dps_val: true
          value: "heat"
          icon: "mdi:radiator"
        - dps_val: false
          value: "off"
          icon: "mdi:radiator-disabled"
    - id: 2
      name: temperature
      type: integer
      range:
        min: 5
        max: 30
    - id: 3
      name: current_temperature
      type: integer
      readonly: true
    - id: 4
      name: preset_mode
      type: integer
      mapping:
        - dps_val: 1
          value: "Home"
        - dps_val: 2
          value: "Away"
        - dps_val: 3
          value: "Smart"
        - dps_val: 4
          value: "Sleep"
    - id: 12
      type: bitfield
      name: error
      mapping:
        - dps_val: 0
          value: OK
    - id: 101
      type: integer
      name: temperature_external_sensor
      readonly: true
    - id: 102
      type: integer
      name: sensor_to_use
      mapping:
        - dps_val: 0
          value: "Internal"
        - dps_val: 1
          value: "External"
        - dps_val: 2
          value: "Internal & External"
    - id: 103
      type: integer
      name: temperature_calibration_offset
      range:
        min: -9
        max: 9
    - id: 104
      type: integer
      name: temperature_calibration_swing
      range:
        min: 1
        max: 9
    - id: 105
      type: boolean
      name: heating_switch_state
      mapping:
        - dps_val: true
          icon: "mdi:thermometer"
        - dps_val: false
          icon: "mdi:thermometer-off"
      readonly: true
    - id: 107
      type: boolean
      name: unknown_107
    - id: 108
      type: boolean
      name: unknown_108
    - id: 110
      type: integer
      name: unknown_110
secondary_entities:
  - entity: lock
    name: Child Lock
    dps:
      - id: 6
        type: boolean
        name: child_lock
        mapping:
          - dps_val: true
            icon: "mdi:account-lock"
          - dps_val: false
            icon: "mdi:account"

I've expected the child lock to become an extra switch that i could add to the "Simple Thermostat" custom implementation

image

Can you explain where i am going wrong with this?

make-all commented 2 years ago

I don't know anything about the "Simple Thermostat" custom implementation, but the child lock should appear in Home Assistant as a lock entity, which can be added to lovelace.

ed-holland commented 2 years ago

I did not find any lock entry. image.

Simple Thermostat I've updated the image above with the latest view.

make-all commented 2 years ago

For dps 105, I am adding hvac_action support from the standard HA climate API, so I suggest changing it to:

    - id: 105
      type: boolean
      name: hvac_action
      mapping:
        - dps_val: true
          value: heating
          icon: "mdi:thermometer"
        - dps_val: false
          constraint: hvac_mode
          conditions:
              - dps_val: true
                 value: idle
              - dps_val: false
                value: "off"
          icon: "mdi:thermometer-off"
      readonly: true

I'm not sure which icons you intended to be used - the ones on there, or the ones for hvac_mode. Without priorities, the icons may not be consistently selected from either.

make-all commented 2 years ago

I see now the issue with the Child Lock. A lock entity is required to have a dps named "lock" to control the lock with. You have made the name "child_lock".

make-all commented 2 years ago

Support is released in 0.10.1

I renamed some of the extra attributes, so you may need to tweak your front end to match.

ed-holland commented 2 years ago

You are faster then i am. Thanks.

It is working nicely.

image