How to adjust scan interval with the new TPlink component

I just updated my test pi to the new .89 component for the TP-link devices. In the previous setup I had been using a scan_interval for each of the two switches to poll the status every 3 seconds due to the frequency of use of these switches and some automations I have. With the new component I cannot use the scan_interval as a way to have HASSIO poll the status (I get errors), and these fricken switches dont get scanned but once every 30 seconds or so by default. Is there any other way I can get the system to scan them more frequently? These two switches get used frequently, and some automations use motion detection to turn them on and off in the middle of the night so they donā€™t wake people.

Thanks in advance.

3 Likes

There is a TP link node for NodeRED and you are able to set the Poll interval in NodeRED, however a better option may be to feature request that ā€˜scan_intervalā€™ be implemented in the new TP link platform

Try interval_seconds

I will do the feature request. I have played around with NodeRed, but thatā€™s about as far as its gone.

Thanks for the reply

No problem, while it could be done in NodeRED, itā€™s a pretty complex solution to a simple problem.

The easiest option would be to roll back to an older version of HA with the old TP link components if you need a short term fix.

1 Like

does interval_seconds work?

tplink:
    switch:
        - host: 192.168.2.35
          interval_seconds: 5

I tried this, and it did not work. I only want a single energy monitor outlet switch (TP-Link model HS-110) to poll fast. I have it connected to an old Bose sound system controlled with an IR blaster, and on/off is a toggle - so to tell if it is on or off I have implemented a sensor switch that bases itā€™s state on the energy use of the bose sound system. But I donā€™t want to wait 30 seconds to figure out if it is on or not - so I want to poll it fast, and I cannot figure out how to do it in 0.89.1

Error is: Invalid config for [tplink]: [interval_seconds] is an invalid option for [tplink]. Check: tplink->tplink->switch->0->interval_seconds. (See /home/homeassistant/.homeassistant/configuration.yaml, line 426). Please check the docs at https://home-assistant.io/components/tplink/

Update: I was able to get the scan interval to 5 seconds using customize.

customize_glob: 
    switch.bose_amp:
        scan_interval: 5
        # interval_seconds: 5

I tried both and config check did not complain, but the scan_interval:5 works fine with config (if I look at the switch card it shows a scan interval of 5)

Update 2: Config accepts it, and the switch card shows scan_interval is 5, but the actual scan interval is still slow (30 seconds). Same is true with interval_seconds: 5 specified. It shows up as an attribute in the switch card (in the web ui) but the scan interval remains at 30 seconds.

I perhaps misunderstood, I thought we were talking about the presence detection tp-link component, which is why I suggested that interval_seconds might be relevant.

My stable PI is running the previous release. I have a ā€œTest piā€ that I test every new release on to see if it functions as I need it to, and to figure out how to get any breaking changes fixed. the term ā€œhappy wife, happy lifeā€ prompted this lol.

I had an automation that checked the power usage of a switch every 3 seconds, and did something when over a certain usage. With this new component, that automation reacts much more slowly.

From @Bruce0ā€™s testing it looks like this isnā€™t possible any more. Anyone else have any ideas? Does this need to be added as a feature request?

Inserting scan_interval and interval_seconds does not work (and oddly seems to cause my HS-110 to go offline too). However there is a solution for most of us:

https://github.com/home-assistant/home-assistant/issues/21768#issuecomment-470959458

Call the service homeassistant.update_entity , it does update the power usage immediately (the HS-110 does some internal averaging so it takes 2 to 3 seconds for the power use feedback to fall (although turn-on feedback seems immediate).

In comment referenced @ljmerza creates a scanning operation by running an automation every 5 seconds. But for me, I just updated the automation that required the data to do the homeassistant.update prior to trying to turn on the switch (if I was turning off I would insert a 3 second delay). So now I am not fast polling but the test of whether the bose system is on works fine so overall performance has improved with no fast polling.

1 Like

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.