Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene support for lights. #146

Merged
merged 9 commits into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following Tuya device types are currently supported:
* Fans
* Climates (soon)

Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices.
Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices.

This repository's development has substantially started by utilizing and merging code from NameLessJedi, mileperhour and TradeFace, and then was deeply refactored to provide proper integration with Home Assistant environment, adding config flow and other features. Refer to the "Thanks to" section below.

Expand Down Expand Up @@ -56,7 +56,7 @@ localtuya:
currpos_dps: 3 # Optional, required only for "position" mode
setpos_dps: 4 # Optional, required only for "position" mode
span_time: 25 # Full movement time: Optional, required only for "fake" mode

- platform: fan
friendly_name: Device Fan
id: 3
Expand All @@ -67,11 +67,13 @@ localtuya:
color_mode: 21 # Optional, usually 2 or 21, default: "none"
brightness: 22 # Optional, usually 3 or 22, default: "none"
color_temp: 23 # Optional, usually 4 or 23, default: "none"
color: 24 # Optional, usually 5 (RGB_HSV) or 24(HSV), default: "none"
color: 24 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none"
brightness_lower: 29 # Optional, usually 0 or 29, default: 29
brightness_upper: 1000 # Optional, usually 255 or 1000, default: 1000
color_temp_min_kelvin: 2700 # Optional, default: 2700
color_temp_max_kelvin: 6500 # Optional, default: 6500
scene: 25 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none"
music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False"


- platform: sensor
Expand All @@ -88,7 +90,7 @@ localtuya:
current_consumption: 19 # Optional
voltage: 20 # Optional
```

Note that a single device can contain several different entities. Some examples:
- a cover device might have 1 (or many) cover entities, plus a switch to control backlight
- a multi-gang switch will contain several switch entities, one for each gang controlled
Expand All @@ -98,12 +100,12 @@ Restart Home Assistant when finished editing.
# 2. Using config flow

Start by going to Configuration - Integration and pressing the "+" button to create a new Integration, then select LocalTuya in the drop-down menu.
Wait for 6 seconds for the scanning of the devices in your LAN. Then, a drop-down menu will appear containing the list of detectes devices: you can
Wait for 6 seconds for the scanning of the devices in your LAN. Then, a drop-down menu will appear containing the list of detectes devices: you can
select one of these, or manually input all the parameters.

![discovery](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/1-discovery.png)

If you have selected one entry, you just have to input the Friendly Name of the Device, and the localKey.
If you have selected one entry, you just have to input the Friendly Name of the Device, and the localKey.
Once you press "Submit", the connection will be tested to check that everything works, in order to proceed.

![device](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/2-device.png)
Expand All @@ -113,8 +115,8 @@ After you have defined all the needed entities leave the "Do not add more entiti

![entity_type](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/3-entity_type.png)

For each entity, the associated DP has to be selected. All the options requiring to select a DP will provide a drop-down menu showing
all the avaliable DPs found on the device (with their current status!!) for an easy identification. Each entity type has different options
For each entity, the associated DP has to be selected. All the options requiring to select a DP will provide a drop-down menu showing
all the avaliable DPs found on the device (with their current status!!) for an easy identification. Each entity type has different options
to be configured, here is an example for the "switch" entity:

![entity](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/4-entity.png)
Expand All @@ -130,23 +132,23 @@ Energy monitoring (voltage, current...) values can be obtained in two different
1) creating individual sensors, each one with the desired name. Note: Voltage and Consumption usually include the first decimal, so 0.1 as "scaling" parameter shall be used in order to get the correct values.
2) accessing the voltage/current/current_consumption attributes of a switch, and then defining template sensors like this (please note that in this case the values are already divided by 10 for Voltage and Consumption):

```
```
sensor:
- platform: template
sensors:
tuya-sw01_voltage:
value_template: >-
{{ states.switch.sw01.attributes.voltage }}
unit_of_measurement: 'V'
unit_of_measurement: 'V'
tuya-sw01_current:
value_template: >-
value_template: >-
{{ states.switch.sw01.attributes.current }}
unit_of_measurement: 'mA'
unit_of_measurement: 'mA'
tuya-sw01_current_consumption:
value_template: >-
{{ states.switch.sw01.attributes.current_consumption }}
unit_of_measurement: 'W'
```
unit_of_measurement: 'W'
```

# Debugging

Expand All @@ -165,9 +167,9 @@ logger:

# To-do list:

* Create a (good and precise) sensor (counter) for Energy (kWh) -not just Power, but based on it-.
* Create a (good and precise) sensor (counter) for Energy (kWh) -not just Power, but based on it-.
Ideas: Use: https://www.home-assistant.io/components/integration/ and https://www.home-assistant.io/components/utility_meter/

* Everything listed in https://github.com/rospogrigio/localtuya-homeassistant/issues/15

# Thanks to:
Expand Down
1 change: 1 addition & 0 deletions custom_components/localtuya/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CONF_COLOR_MODE = "color_mode"
CONF_COLOR_TEMP_MIN_KELVIN = "color_temp_min_kelvin"
CONF_COLOR_TEMP_MAX_KELVIN = "color_temp_max_kelvin"
CONF_MUSIC_MODE = "music_mode"

# switch
CONF_CURRENT = "current"
Expand Down
Loading