make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.22k stars 490 forks source link

Enhancement: Add Power Consumption and Manual Override to Arlec Smart Thermostat Socket #535

Closed thewolf-oz closed 1 year ago

thewolf-oz commented 1 year ago

Hi there

The Arlec Smart Thermostat Socket (arlec_thermostat_smartplug.yaml) supports manual override of power. I use it in this way so I've got a smart socket and thermometer in one and don't actually use it as a thermostat. It would also be nice to have the power consumption like the other thermostat socket

I've amended the code on my instance with the below:

make-all commented 1 year ago

Is the electricity consumption actually a reliable energy meter? I deliberately left this as an attribute on the power sensor entity to avoid misleading users, since "add_ele" attributes on other Tuya smartplugs tend to auto-reset immediately after sending to the cloud, making them useless in practice for local use.

The log in #499 did not show a dp with id "1", is this a different device, or are there specific circumstances where this master switch shows up?

thewolf-oz commented 1 year ago

I’m not sure if the cloud version adds from each report or if it is cumulative from the device, I did see this in another similar device (that this integration suggested) and modified the yaml

The device has a manual mode which disables the automations. I use these exclusively in this mode and use the temperature/humidity as data points rather than an inbuilt automation

I will gather the DPS from the Tuya IOT page when I get home like the fans I submitted

F2988CC7-A763-4CD1-8E4C-C3D6C98B941F 7CC4F836-F7FD-4988-8BAD-00462095C6E7

make-all commented 1 year ago

So the dp 1 switch is available when dp 9 "Customize mode" is switched off, maybe? And the climate controls should only really be operational when it is on? (I don't think I can actually do the last one, as they are already cross dependent on two different dps, but I guess users will mostly use one or the other and can just remove the unused control from their dashboard, replacing the climate gauge with a simpler temperature display)

thewolf-oz commented 1 year ago

I just confirmed same model device. The operation you suggest sounds about right. There's actually a heap of DPs for this one. Looking at the Temperature DPs, it appears there are unique DPs for Celsius or Farenheit... I could see the reported values for 27 and 28 had the units encoded so I assume 21 and 22 correlate. I'm happy to do some testing switching between modes etc and looking at the IOT logs if required

I also assume that 55 and 56 enable once you select Cold, with the switch enabling/disabling the "compressor delay" as used for fridges being turned on and off (like the Inkbird 308 wifi has, which I also have)

2 - Switch

4 - Countdown

7 - Schedule

8 - Work Mode

9 - Mode Switch (On/Off)

10 - Add Ele (mentions kW/h)

11 - Cur Current

12 - Cur Power

13 - Cur Voltage

14 - Voltage COE

15 - Electric COE

16 - Power COE

17 - Electricity COE

18 - Power Limit

19 - Test Bit

20 - Test Unit Convert

21 - Target Temperature

22 - Target Temperature

27 - Temperature (C)

28 - Temperature (F)

29 - Vibration Value

30 - Temp Correction

41 - Humidity Set

42 - Humidity Range

46 - Humidity Value

47 - Humidity Calibration

50 - Fault

55 - Cold Delay

56 - Cold Delay Switch

make-all commented 1 year ago

To confirm whether add_ele is usable, you can view the detailed state of the power sensor in Developer Tools. If it is giving a large value that periodically increments, then it should be usable as an energy sensor. But if it mostly reads 0, and occasionally 1 or 100 then back to 0, then it is not really usable, and should be left as an attribute.

thewolf-oz commented 1 year ago

Yeah, it looks like it is power used in the last reporting period: image

I'm OK to exclude it if it's too difficult, however the manual override is probably the more important addition as far as I'm concerned. I think the power used can be used with a statistics sensor to add it up as an energy meter

make-all commented 1 year ago

Yes, the power can be used with an integration helper to get a Reimann sum integral for use on the energy dashboard.

thewolf-oz commented 1 year ago

Thanks! Looking forward to testing this in the morning!

thewolf-oz commented 1 year ago

I've just tested this and I don't think it is working as expected (definitely, not as I expected). When the Climate control is off, I still see no option to switch the socket on and off manually image

On a side note (and happy to raise another request), the "wet" description you've got of "Fan only" is probably incorrect in this context. This setting is designed to be used with a humidifier to increase the humidity on that setting. The app uses "Hum" and "Dehum" to fit into the space and indicate Humidify/Dehumidify image image BFB01009-9A7A-430D-9B0E-233A912E062F

make-all commented 1 year ago

Home Assistant climate platform does not support humidifier modes, so i used fan_only for that (as it is the only mode left unused). So if you want to send a bug report, send it to Home Assistant requesting humidify be added to the hvac modes, and make it clear this is a single device that supports all those modes, so using a humidifier entity is not possible.

For the switch, I am not sure why it is not showing up, reviewing the config it looks correct. Is there anything in the log that shows why Home Assistant is rejecting it?

make-all commented 1 year ago

Can you grab the diagnostics from Settings / Devices & Services / Tuya Local / 1 device / Download Diagnostics.

This will have some info on what is going on internally in Home Assistant.

thewolf-oz commented 1 year ago

As it turns out, I used the smoker today. Turning it on manually in the Tuya App (actually by the Google Home integration), this integration showed "Dry"

image

Diagnostics below: { "home_assistant": { "installation_type": "Home Assistant OS", "version": "2023.3.3", "dev": false, "hassio": true, "virtualenv": false, "python_version": "3.10.10", "docker": true, "arch": "x86_64", "timezone": "Australia/Sydney", "os_name": "Linux", "os_version": "5.15.90", "supervisor": "2023.03.1", "host_os": "Home Assistant OS 9.5", "docker_version": "20.10.22", "chassis": "embedded", "run_as_root": true }, "custom_components": { "nest_protect": { "version": "0.3.8", "requirements": [] }, "cellar_tracker": { "version": "20210413", "requirements": [ "cellartracker" ] }, "sems": { "version": "3.7.2", "requirements": [] }, "localtuya": { "version": "5.0.0", "requirements": [] }, "browser_mod": { "version": "2.2.0", "requirements": [] }, "upnp_availability": { "version": "0.0.3", "requirements": [ "async_upnp_client>=0.33" ] }, "hacs": { "version": "1.31.0", "requirements": [ "aiogithubapi>=22.10.1" ] }, "solcast_solar": { "version": "3.0.42", "requirements": [ "aiohttp>=3.6.2", "datetime>=4.3", "isodate>=0.6.0" ] }, "formulaone_api": { "version": "0.1.11", "requirements": [ "requests>=2.20" ] }, "edge_tts": { "version": "0.0.1", "requirements": [ "edge-tts==6.1.3" ] }, "tuya_local": { "version": "2022.3.0", "requirements": [ "pycryptodome~=3.17", "tinytuya==1.11.0" ] }, "bureau_of_meteorology": { "version": "1.1.18", "requirements": [ "iso8601" ] }, "alexa_media": { "version": "4.6.2", "requirements": [ "alexapy==1.26.5", "packaging>=20.3", "wrapt>=1.12.1" ] }, "anniversaries": { "version": "5.2.0", "requirements": [ "python-dateutil>=2.8.1", "integrationhelper>=0.2.2", "voluptuous>=0.12.1" ] }, "garbage_collection": { "version": "4.10.2", "requirements": [ "python-dateutil>=2.8.2" ] }, "smartthinq_sensors": { "version": "0.31.4", "requirements": [ "pycountry>=20.7.3", "xmltodict>=0.12.0", "cchardet>=2.1.7" ] }, "webrtc": { "version": "v3.1.0", "requirements": [] }, "rapt_ble": { "version": "0.1.0", "requirements": [ "rapt-ble==0.1.0" ] }, "eufy_security": { "version": "6.2.0", "requirements": [ "websocket-client==1.1.0", "aiortsp==1.3.6" ] }, "watchman": { "version": "0.5.1", "requirements": [ "prettytable==3.0.0" ] } }, "integration_manifest": { "domain": "tuya_local", "name": "Tuya Local", "codeowners": [ "@make-all" ], "config_flow": true, "dependencies": [], "documentation": "https://github.com/make-all/tuya-local", "integration_type": "device", "iot_class": "local_push", "issue_tracker": "https://github.com/make-all/tuya-local/issues", "requirements": [ "pycryptodome~=3.17", "tinytuya==1.11.0" ], "version": "2022.3.0", "is_built_in": false }, "data": { "name": "Smoker", "type": "arlec_thermostat_smartplug", "device_id": "REDACTED", "local_key": "REDACTED", "host": "REDACTED", "protocol_version": "auto", "api_version_set": 3.3, "api_version_used": 3.3, "api_working": true, "status": {}, "cached_state": { "updated_at": 1679219286.386872, "2": false, "4": 0, "7": "", "8": "dehumidify", "9": false, "10": 1, "11": 0, "12": 0, "13": 2338, "14": 573, "15": 23372, "16": 12745, "17": 3260, "18": 36000, "19": 1, "20": "c", "21": 950, "22": 350, "27": 295, "28": 851, "29": 20, "30": 0, "41": 50, "42": 4, "46": 62, "47": 0, "50": 0, "55": 2, "56": false }, "pending_state": {}, "connected": true, "force_dps": [], "home_assistant": { "name": "Smoker", "name_by_user": null, "disabled": false, "disabled_by": null, "entities": [ { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": null, "state": { "entity_id": "select.smoker_temperature_unit", "state": "Celsius", "attributes": { "options": [ "Celsius", "Fahrenheit" ], "icon": "mdi:temperature-celsius", "friendly_name": "Smoker Temperature unit" }, "last_changed": "2023-03-18T23:32:41.189647+00:00", "last_updated": "2023-03-18T23:32:41.189647+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": "min", "state": { "entity_id": "number.smoker_timer", "state": "0.0", "attributes": { "min": 0.0, "max": 1440.0, "step": 1.0, "mode": "auto", "unit_of_measurement": "min", "icon": "mdi:timer", "friendly_name": "Smoker Timer" }, "last_changed": "2023-03-18T23:32:41.190872+00:00", "last_updated": "2023-03-18T23:32:41.190872+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": null, "state": { "entity_id": "number.smoker_temperature_hysteresis", "state": "2.0", "attributes": { "min": 1.0, "max": 9.0, "step": 0.5, "mode": "auto", "unit_of_measurement": "\u00b0C", "icon": "mdi:arrow-collapse-vertical", "friendly_name": "Smoker Temperature hysteresis" }, "last_changed": "2023-03-18T23:32:41.191120+00:00", "last_updated": "2023-03-18T23:32:41.191120+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": null, "state": { "entity_id": "number.smoker_temperature_correction", "state": "0", "attributes": { "min": -9, "max": 9, "step": 1.0, "mode": "auto", "unit_of_measurement": "\u00b0C", "icon": "mdi:pan-vertical", "friendly_name": "Smoker Temperature correction" }, "last_changed": "2023-03-18T23:32:41.191395+00:00", "last_updated": "2023-03-18T23:32:41.191395+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": "%", "state": { "entity_id": "number.smoker_humidity_hysteresis", "state": "4", "attributes": { "min": 2, "max": 20, "step": 2.0, "mode": "auto", "unit_of_measurement": "%", "icon": "mdi:arrow-collapse-vertical", "friendly_name": "Smoker Humidity hysteresis" }, "last_changed": "2023-03-18T23:32:41.191608+00:00", "last_updated": "2023-03-18T23:32:41.191608+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": "%", "state": { "entity_id": "number.smoker_humidity_correction", "state": "0", "attributes": { "min": -9, "max": 9, "step": 1.0, "mode": "auto", "unit_of_measurement": "%", "icon": "mdi:pan-vertical", "friendly_name": "Smoker Humidity correction" }, "last_changed": "2023-03-18T23:32:41.191761+00:00", "last_updated": "2023-03-18T23:32:41.191761+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": "min", "state": { "entity_id": "number.smoker_cold_delay", "state": "2", "attributes": { "min": 0, "max": 10, "step": 1.0, "mode": "auto", "unit_of_measurement": "min", "icon": "mdi:camera-timer", "friendly_name": "Smoker Cold delay" }, "last_changed": "2023-03-18T23:32:41.191899+00:00", "last_updated": "2023-03-18T23:32:41.191899+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": "switch", "icon": null, "unit_of_measurement": null, "state": { "entity_id": "switch.smoker_cold_delay_enable", "state": "off", "attributes": { "device_class": "switch", "icon": "mdi:camera-timer", "friendly_name": "Smoker Cold delay enable" }, "last_changed": "2023-03-18T23:34:10.822600+00:00", "last_updated": "2023-03-18T23:34:10.822600+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "diagnostic", "device_class": null, "original_device_class": "problem", "icon": null, "unit_of_measurement": null, "state": { "entity_id": "binary_sensor.smoker_fault", "state": "off", "attributes": { "device_class": "problem", "friendly_name": "Smoker Fault" }, "last_changed": "2023-03-18T23:32:41.189810+00:00", "last_updated": "2023-03-18T23:32:41.189810+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": null, "device_class": null, "original_device_class": null, "icon": null, "unit_of_measurement": null, "state": { "entity_id": "climate.smoker", "state": "off", "attributes": { "hvac_modes": [ "off", "dry", "heat", "cool", "fan_only" ], "min_temp": -20.0, "max_temp": 105.0, "target_temp_step": 0.5, "min_humidity": 1, "max_humidity": 99, "current_temperature": 29.5, "temperature": 35.0, "current_humidity": 62, "humidity": 50, "cycle_time": "", "factory_test": 1, "fault_code": 0, "friendly_name": "Smoker", "supported_features": 5 }, "last_changed": "2023-03-19T09:48:06.271581+00:00", "last_updated": "2023-03-19T09:48:06.271581+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "diagnostic", "device_class": null, "original_device_class": "current", "icon": null, "unit_of_measurement": "mA", "state": { "entity_id": "sensor.smoker_current", "state": "0", "attributes": { "state_class": "measurement", "calibration": 23372, "unit_of_measurement": "mA", "device_class": "current", "friendly_name": "Smoker Current" }, "last_changed": "2023-03-19T08:39:22.646190+00:00", "last_updated": "2023-03-19T08:39:22.646190+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "diagnostic", "device_class": null, "original_device_class": "power", "icon": null, "unit_of_measurement": "W", "state": { "entity_id": "sensor.smoker_power", "state": "0.0", "attributes": { "state_class": "measurement", "add_ele": 1, "ele_calibration": 3260, "calibration": 12745, "limit": 3600.0, "unit_of_measurement": "W", "device_class": "power", "friendly_name": "Smoker Power" }, "last_changed": "2023-03-19T08:39:22.647681+00:00", "last_updated": "2023-03-19T09:18:18.382819+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "diagnostic", "device_class": null, "original_device_class": "voltage", "icon": null, "unit_of_measurement": "V", "state": { "entity_id": "sensor.smoker_voltage", "state": "233.8", "attributes": { "state_class": "measurement", "calibration": 573, "unit_of_measurement": "V", "device_class": "voltage", "friendly_name": "Smoker Voltage" }, "last_changed": "2023-03-19T09:39:24.150146+00:00", "last_updated": "2023-03-19T09:39:24.150146+00:00" } }, { "disabled": false, "disabled_by": null, "entity_category": "config", "device_class": null, "original_device_class": "switch", "icon": null, "unit_of_measurement": null, "state": { "entity_id": "switch.smoker_climate_mode", "state": "off", "attributes": { "device_class": "switch", "icon": "mdi:toggle-switch", "friendly_name": "Smoker Climate mode" }, "last_changed": "2023-03-18T23:43:42.635411+00:00", "last_updated": "2023-03-18T23:43:42.635411+00:00" } } ] } } }

make-all commented 1 year ago

Based on the diagnostics, it looks like there is no dp 1 as a separate switch, probably what is actually needed is to access dp 2 as a simple switch when in manual mode.

thewolf-oz commented 1 year ago

Have now had a bit of a play with one, and it appears that the following works. The device handles the switch as a manual override and when in an automatic mode, the device reports it's on/off state back to HA primary_entity: entity: climate dps:

image image image image

thewolf-oz commented 1 year ago

FYI - happy to do this as a pull request if that's easier now that I've tweaked the above, figured I should respond here regardless

make-all commented 1 year ago

Yes, using dp 9 for the climate switch instead of dp 2 might be better. Are there any other changes? It might be easier to see what the actual changes are in a PR.

thewolf-oz commented 1 year ago

That’s all I did, but now I’ve setup the fork I’ll do the PR with the full file that I have working when I get home from work tonight

thewolf-oz commented 1 year ago

Sorry for the delay. PR created here: https://github.com/make-all/tuya-local/pull/589