Skip to content

Commit

Permalink
Set scan_interval for localtuya lights
Browse files Browse the repository at this point in the history
Workaround for rospogrigio/localtuya#445, at least until rospogrigio/localtuya#491 is merged.
  • Loading branch information
joshuaspence committed Feb 24, 2022
1 parent 6e2eb29 commit 2a61cb9
Showing 1 changed file with 5 additions and 139 deletions.
144 changes: 5 additions & 139 deletions packages/tuya.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ localtuya:
device_id: !secret 'tuya.attic_ridge.device_id'
local_key: !secret 'tuya.attic_ridge.local_key'
friendly_name: 'Attic Ridge Light Strip'
scan_interval: 120
entities:
- platform: 'light'
friendly_name: 'Attic Ridge'
Expand All @@ -18,6 +19,7 @@ localtuya:
device_id: !secret 'tuya.attic_1.device_id'
local_key: !secret 'tuya.attic_1.local_key'
friendly_name: 'Attic Light Strip 1'
scan_interval: 120
entities:
- platform: 'light'
friendly_name: 'Attic 1'
Expand All @@ -27,6 +29,7 @@ localtuya:
device_id: !secret 'tuya.attic_2.device_id'
local_key: !secret 'tuya.attic_2.local_key'
friendly_name: 'Attic Light Strip 2'
scan_interval: 120
entities:
- platform: 'light'
friendly_name: 'Attic 2'
Expand All @@ -36,6 +39,7 @@ localtuya:
device_id: !secret 'tuya.attic_3.device_id'
local_key: !secret 'tuya.attic_3.local_key'
friendly_name: 'Attic Light Strip 3'
scan_interval: 120
entities:
- platform: 'light'
friendly_name: 'Attic 3'
Expand All @@ -45,6 +49,7 @@ localtuya:
device_id: !secret 'tuya.bedroom_1_ceiling_projector.device_id'
local_key: !secret 'tuya.bedroom_1_ceiling_projector.local_key'
friendly_name: 'Bedroom 1 Ceiling Projector'
scan_interval: 120
entities:
- platform: 'switch'
friendly_name: 'Bedroom 1 Ceiling Projector'
Expand Down Expand Up @@ -88,142 +93,3 @@ automation:
dp: 51
value: 'manual'
max_exceeded: 'silent'

# Workaround for rospogrigio/localtuya#445.
- id: '64a22f6e-a3e7-49b8-a83e-92a624417769'
alias: 'Refresh Tuya Devices'
trigger:
platform: 'state'
entity_id:
- 'binary_sensor.ping_attic_ridge_light_strip'
- 'binary_sensor.ping_attic_light_strip_1'
- 'binary_sensor.ping_attic_light_strip_2'
- 'binary_sensor.ping_attic_light_strip_3'
- 'binary_sensor.ping_bedroom_1_ceiling_projector'
from: 'off'
to: 'on'
action:
choose:
- conditions: '{{ trigger.entity_id == "binary_sensor.ping_attic_ridge_light_strip" }}'
sequence:
service: 'script.refresh_tuya_device'
data:
entity_id: 'light.attic_ridge'
data:
24: '007803e803e8'
<<: &common_dps
20: false
21: 'white'
22: 1000
23: 328
- conditions: '{{ trigger.entity_id == "binary_sensor.ping_attic_light_strip_1" }}'
sequence:
service: 'script.refresh_tuya_device'
data:
entity_id: 'light.attic_1'
data: *common_dps
- conditions: '{{ trigger.entity_id == "binary_sensor.ping_attic_light_strip_2" }}'
sequence:
service: 'script.refresh_tuya_device'
data:
entity_id: 'light.attic_2'
data: *common_dps
- conditions: '{{ trigger.entity_id == "binary_sensor.ping_attic_light_strip_3" }}'
sequence:
service: 'script.refresh_tuya_device'
data:
entity_id: 'light.attic_3'
data: *common_dps
- conditions: '{{ trigger.entity_id == "binary_sensor.ping_bedroom_1_ceiling_projector" }}'
sequence:
- service: 'script.refresh_tuya_device'
data:
entity_id: 'switch.bedroom_1_ceiling_projector'
data:
20: false
- service: 'script.refresh_tuya_device'
data:
entity_id: 'light.bedroom_1_ceiling_projector_light'
data:
24: '0000000003e8'
51: 'manual'
52: true
- service: 'script.refresh_tuya_device'
data:
entity_id: 'light.bedroom_1_ceiling_projector_laser'
data:
53: true
54: 1000
- service: 'script.refresh_tuya_device'
data:
entity_id: 'light.bedroom_1_ceiling_projector_motor'
data:
60: true
62: 100
mode: 'parallel'
max: 10

# Only needed by `automation.refresh_tuya_devices`.
binary_sensor:
- platform: 'ping'
host: *attic_ridge_host
name: 'Ping Attic Ridge Light Strip'
scan_interval: 60
- platform: 'ping'
host: *attic_1_host
name: 'Ping Attic Light Strip 1'
scan_interval: 60
- platform: 'ping'
host: *attic_2_host
name: 'Ping Attic Light Strip 2'
scan_interval: 60
- platform: 'ping'
host: *attic_3_host
name: 'Ping Attic Light Strip 3'
scan_interval: 60
- platform: 'ping'
host: *bedroom_1_ceiling_projector_host
name: 'Ping Bedroom 1 Ceiling Projector'
scan_interval: 60

# Only needed by `automation.refresh_tuya_devices`.
script:
refresh_tuya_device:
alias: 'Refresh Tuya Device'
icon: 'mdi:restart'
fields:
entity_id:
name: 'Entity ID'
required: true
selector:
entity:
integration: 'localtuya'
data:
name: 'Data Points'
required: true
selector:
object: null
variables:
device_id: '{{ (device_attr(entity_id, "identifiers") | selectattr("0", "eq", "localtuya") | first | last).split("_")[-1] }}'
sequence:
- condition: 'template'
value_template: '{{ states(entity_id) == "unavailable" }}'
- service: 'system_log.write'
data:
message: 'Refreshing Tuya device {{ device_id }} for entity {{ entity_id }}'
- service: 'logger.set_level'
data:
custom_components.localtuya: 'error'
- repeat:
count: '{{ data | length }}'
sequence:
service: 'localtuya.set_dp'
data:
device_id: '{{ device_id }}'
dp: '{{ (data.keys() | list)[repeat.index - 1] }}'
value: '{{ (data.values() | list)[repeat.index - 1] }}'
- service: 'logger.set_level'
data:
custom_components.localtuya: 'notset'
mode: 'parallel'
max: 10

0 comments on commit 2a61cb9

Please sign in to comment.