rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.71k stars 530 forks source link

Add X-Sense smoke sensor to LocalTuya #786

Open jmcollin78 opened 2 years ago

jmcollin78 commented 2 years ago

There is one X-Sense (very frequent) smoke sensor logs. It will be really great to have this in Local Tuya.

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.3.8",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Paris",
    "os_name": "Linux",
    "os_version": "5.10.103",
    "supervisor": "2022.03.5",
    "host_os": "Home Assistant OS 7.5",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "pyscript": {
      "version": "1.3.3",
      "requirements": [
        "croniter==1.3.4",
        "watchdog==2.1.6"
      ]
    },
    "meross_cloud": {
      "version": "1.2.0rc2",
      "requirements": [
        "meross_iot==0.4.4.4"
      ]
    },
    "var": {
      "version": "0.12.3",
      "requirements": []
    },
    "scheduler": {
      "version": "v0.0.0",
      "requirements": []
    },
    "hacs": {
      "version": "1.22.0",
      "requirements": [
        "aiogithubapi>=21.11.0"
      ]
    },
    "sonoff": {
      "version": "v2.4.6",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "localtuya": {
      "version": "3.2.1",
      "requirements": []
    },
    "meross_lan": {
      "version": "2.5.7",
      "requirements": []
    },
    "tesla_custom": {
      "version": "1.7.0",
      "requirements": [
        "teslajsonpy==1.10.0"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya",
    "name": "Tuya",
    "documentation": "https://www.home-assistant.io/integrations/tuya",
    "requirements": [
      "tuya-iot-py-sdk==0.6.6"
    ],
    "dependencies": [
      "ffmpeg"
    ],
    "codeowners": [
      "@Tuya",
      "@zlinoliver",
      "@METISU",
      "@frenck"
    ],
    "config_flow": true,
    "iot_class": "cloud_push",
    "dhcp": [
      {
        "macaddress": "105A17*"
      },
      {
        "macaddress": "10D561*"
      },
      {
        "macaddress": "1869D8*"
      },
      {
        "macaddress": "381F8D*"
      },
      {
        "macaddress": "508A06*"
      },
      {
        "macaddress": "68572D*"
      },
      {
        "macaddress": "708976*"
      },
      {
        "macaddress": "7CF666*"
      },
      {
        "macaddress": "84E342*"
      },
      {
        "macaddress": "D4A651*"
      },
      {
        "macaddress": "D81F12*"
      }
    ],
    "loggers": [
      "tuya_iot"
    ],
    "is_built_in": true
  },
  "data": {
    "endpoint": "https://openapi.tuyaeu.com",
    "auth_type": 0,
    "country_code": "33",
    "app_type": "smartlife",
    "mqtt_connected": null,
    "disabled_by": null,
    "disabled_polling": false,
    "name": "D\u00e9tecteur fum\u00e9e sam",
    "model": "xs01(WIFI)",
    "category": "ywbj",
    "product_id": "skivkhveqwmqw4gs",
    "product_name": "X-sense WI-FI Smoke Alarm",
    "online": true,
    "sub": false,
    "time_zone": "+01:00",
    "active_time": "2022-04-02T16:36:25+00:00",
    "create_time": "2022-03-09T17:43:23+00:00",
    "update_time": "2022-04-02T16:36:25+00:00",
    "function": {
      "muffling": {
        "type": "Boolean",
        "value": {}
      }
    },
    "status_range": {
      "smoke_sensor_status": {
        "type": "Enum",
        "value": {
          "range": [
            "alarm",
            "normal"
          ]
        }
      },
      "battery_state": {
        "type": "Enum",
        "value": {
          "range": [
            "low",
            "high"
          ]
        }
      },
      "muffling": {
        "type": "Boolean",
        "value": {}
      }
    },
    "status": {
      "smoke_sensor_status": "normal",
      "battery_state": "high",
      "muffling": false
    },
    "home_assistant": {
      "name": "D\u00e9tecteur fum\u00e9e sam",
      "name_by_user": null,
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": "smoke",
          "original_device_class": "smoke",
          "icon": "mdi:smoke-detector-variant",
          "original_icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "binary_sensor.detecteur_fumee_sam",
            "state": "off",
            "attributes": {
              "device_class": "smoke",
              "icon": "mdi:smoke-detector-variant",
              "friendly_name": "D\u00e9tecteur fum\u00e9e sam"
            },
            "last_changed": "2022-04-02T16:45:38.944027+00:00",
            "last_updated": "2022-04-02T16:50:15.995848+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "original_icon": "mdi:battery",
          "unit_of_measurement": null,
          "state": {
            "entity_id": "sensor.detecteur_fumee_sam_battery_state",
            "state": "high",
            "attributes": {
              "icon": "mdi:battery",
              "friendly_name": "D\u00e9tecteur fum\u00e9e sam Battery State"
            },
            "last_changed": "2022-04-02T16:45:53.054045+00:00",
            "last_updated": "2022-04-02T16:45:53.054045+00:00"
          }
        }
      ]
    }
  }
}

When I try manual integration giving the IP and local key, I get this error:

2022-04-03 07:30:28 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception
Traceback (most recent call last):
  File "/config/custom_components/localtuya/config_flow.py", line 283, in async_step_basic_info
    self.dps_strings = await validate_input(self.hass, user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 189, in validate_input
    interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 669, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.1.63', 6668)

This sensor seems to sleep after a certain amount of time and not always listening to http requests. May be this can be a problem for the local tuya integration. It works well with the Cloud Tuya integration.

grizzly1105 commented 2 years ago

Same issue here

garwedgess commented 1 year ago

Also looking for this

LordArrin commented 12 months ago

Waiting for it too.

MiguelAngelGumiel commented 10 months ago

Good morning, looking forward to integration too, thank you.