How to adjust scan interval with the new TPlink component

Thanks for the info, @Bruce0, I was able to get everything working as it was before!
Here is my updated automation config, if anyone’s interested:

- alias: Turn off Air Purifier when loud
  trigger:
  - platform: time_pattern
    seconds: '/3' # every 3 seconds
  action:
  - service: homeassistant.update_entity
    data:
      entity_id: switch.air_purifier
  - condition: or
    conditions:
      condition: numeric_state
      entity_id: switch.air_purifier
      above: '15'
      value_template: '{{ state.attributes.current_power_w }}'
  - service: switch.turn_off
    data:
      entity_id: switch.air_purifier
  - delay: 0:00:01
  - service: switch.turn_on
    data:
      entity_id: switch.air_purifier
2 Likes

You might find a template switch helpful. Using that switch (which is conditional based upon the result of the “current_power_w”, you can then avoid polling. I just call the homeassistant.update before turning a switch on or off (Havent yet figured out how to build that into the template switch) which makes my automations read a lot simpler.

# sensing template switch for bose Cinemate II
  - platform: template
    switches:
      power_bose:
        value_template: '{{ states.switch.bose_amp.attributes.current_power_w > "1.50"  }}'
        turn_on:
          service: homeassistant.turn_on
          data:
            entity_id: switch.power_bose_hidden
        turn_off:
          service: homeassistant.turn_off
          data:
            entity_id: switch.power_bose_hidden
        icon_template: >-
          {% if states.switch.bose_amp.attributes.current_power_w > "1.50" %}
            mdi:speaker
          {% else %}
            mdi:speaker-off
          {% endif %}
1 Like

@Bruce0 could you elaborate a bit on “I just call the homeassistant.update before turning a switch on or off” ?

I am currently trying to have an automation whenever my record player (connected to the TP-Link plug) turns on (meaning when the plug registers current_power_w > 1.5). But currently the HA pulls every 30 seconds, and unless I create a running timer (every 2 seconds) I am not sure how else I could catch the “before turning the switch on-off”.

Key element here is that I want to turn the record player on/off, and not the plug

Hey I figured out a node red solution to this tp link problem that works for me. I have a poll state node, on my switch that is set to poll every 3 seconds it then goes to a [current state] node with domain: home assistant and the service update_entity: switch.tplink then a [RBE] Node then [switch] node then call service to a lamp on or off depending on the original state. it is not the best and i doubt polling is the best thing but its better than the 30 plus seconds i have to wait to get this thing to work originally

@ AlexKalopsia Apologies for the very long delay, I have been away. Here is an example, the first service assures that the status the switch is currently reporting is used.

  - service: homeassistant.update_entity
    data:
      entity_id:
        - switch.bose_amp
  - service: python_script.turn_on_blind_toggle
    data_template:
      { "entity_id": "switch.power_bose" }
  - service: homeassistant.turn_off
    data:
      entity_id: input_boolean.movie_time

I’m a little late to the party, but I thought I’d share what was ultimately the solution for me.

It involved creating the following automation to manually update the state on a predetermined interval for the switches that I specified.

- id: update_tp_link
  initial_state: 'on'
  trigger:
    - platform: time_pattern
      seconds: '/5' # every 5 seconds
  action:
    - service: homeassistant.update_entity
      data:
        entity_id: 
          - light.tp_link_light1
          - light.tp_link_light

All thanks to ljmerza who posted this solution on GitHub.

2 Likes

i’m super new to HA. my coding level is like a 4/10. i’m trying to do a similar thing to OP, i have a switch, when i turn it on, i want a group of switches to come on, and then also a group of switches turn off when the switch is off.
i did it, no problem, but there is a 20-30 second delay which is just really annoying and confusing to guest who will turn the light on and off a few times thinking my system is broken.

my biggest question, is where am i typing this in. i know its a super noob question but i’ve been at this for about 2 weeks and the documentation is very limited (mainly navigation of home assistant)

i added the add-on file editor, i typed in a similar line to this:

customize_glob:
switch.light_1:
scan_interval: 5

i get an error for project name. i guess i’m just asking if anyone can link me or just really dumb down the basic starting point of where to and how to change my scan interval for my TP link switch.

i’m a visual person and i haven’t seen a solid sketch to give me a road map. thanks

@boost4brains What sort of gear are you using. Nothing in HA should take 20 seconds to work.

on the TP link side, 24 hs200s and 3 hs220s, about to be 3, 3 way switches as well. when I select on the panel on in the ha app, its almost instant. its when you manually toggle the switch, it takes up to 20-30 seconds to show on HA and to trigger the events. as soon as the events register on HA the automation happens. I’ve been reading and apparently the default scan for TP link is 30 seconds. on Smartthings, it was almost 5 min.

ultimately i’m trying to get past the 3 automation limit in the tp link app and also control some off brand lights I have hung around the house.

I would say, get a better switch :slight_smile:

I just spent $600+ and 3 days hooking them up. They have potential aside from the shit Kasa app. 3 automations should have been posted in more places or else I would have gone another route. But these are the best looking and go online less than any other switch I’ve tried.

I am running into the same issues. I don’t have quite any many tp link devices (5 currently) but it’s very annoying and frustrating issue. When having tp link connected to my smartthings app, smartthings app notices almost instantly. I physically turn a switch off, the app shows it off within a second or two. I do that same thing with HA and HA will show it off at some point, maybe a minute.

If you’ve figured out a solution or workaround let me know please.
Thanks!

I wish that I would have seen this before I spent a couple of K redoing all of my home with the TPLink switches and dimmers. They seem to work fine other than this. I only have a few that need this function but they are a critical few. The three limit is ridiculous for automation.

Had a problem with Kasa Automation between a Kasa Wall Switch + Kasa Outlet Plug, probably due to a recent AWS outage.
Was able to set up an automation via the UI that just updates the Wall Switch status every 2 seconds.

Based off the earlier post with the YAML settings by @JustMaier
Triggers
Trigger type: Time Pattern
Hour: Blank
Minutes: Blank
Seconds: /3

Actions
Action Type: Call service
Service: homeassistant.update_entity
Entity: (add your switch entity)

1 Like

It seems that it’s suddenly stop working for me.

Hi all,

This solution is working great. Instead of an update every 30 seconds, i get an update every 5 seconds. Perfect. See below the code in code lay-out.

alias: Update TP-Link HS110
description: ''
trigger:
  - platform: time_pattern
    seconds: /5
condition: []
action:
  - service: homeassistant.update_entity
    data:
      entity_id:
        - switch.energiemeter_pc
        - switch.energiemeter_tv
mode: single

As per Home Assistant release 2020.6, there is option to disable the polling of the integration completely, thereby fully residing on your own polling frequency: 2021.6: A little bit of everything - Home Assistant

This gives a small performance benefit: each 30 seconds, an unneeded poll is done via the integration itself, on top of your own defined schedule. By disabling this, you prevent a double poll: 5s single poll > 10s single poll >15s single poll >20s single poll >25s single poll >30s double poll > 35s single poll >etc.

Note: in the release party of 2021.6 (youtube stream), it was mentioned that you should never increase the polling rate as compared to the integration native setting (lower is ok, higher not). Reason being that each integration is already having the optimal value and going higher would introduce negative side-effects. I don’t think this is true for the TP-Link Kasa Smart integration: i think the native setting is suboptimal. I have not seen any negative side effects of a poll once-every-5-seconds.

1 Like

Is there a way to disable the integration polling from within the automation?

30sec polling is ok for me most of the time, and saves space in my HA database. But occasionally I want higher resolution current consumption data, and I’ll toggle the automation on you mentioned to give me 5sec polling interval.

Is there a way to temporarily disable the native polling in the same automation?

I adjusted this with some tempting so I don’t have to list the entities manually. This is working great.

- alias: Update TP-Link Devices
  description: ''
  trigger:
    - platform: time_pattern
      seconds: /5
  condition: []
  action:
    - service: homeassistant.update_entity
      data:
        entity_id: "{{ integration_entities('tplink') }}"
  mode: single
2 Likes

@clinta @pimw Hey this is exactly what I was looking for! A couple automations were running so slow because of the polling time. Did either of you see any negative side effects? I have 35 switches and dimmers and I just might do this. I wonder if that would push the limit.

1 Like

Hi, great to hear. I only have two of these, so i cannot tell you how scalable it is. But in general, polling is less efficient than pushing.

1 Like