Using cookbook examples for a tp-LINK hs100 SMART PLUG

Hi
I’ve got the HS100 configured with kasa and that works, and I can control from the app and see its
ipaddress of 192.168.1.83 on the router. HA is running on a SBC running linux on 192.168.1.82.
Sorry for such a stupid question but what do I need to do next to get HA to see the HS100

like how to add it into configurations.yaml ??
and then do I just rename the section of script in the examples to automations.yaml ???

apologies for the newbie question, but we all start somewhere

thanks
Richard

Hi
I’ve got past that point and loaded the HS100 python module as well
but trying to use the automation script from the examples , the config fails

> automation:
>   trigger:
>     platform: sun
>     event: sunset
>     offset: "-00:45:00"
>   condition:
>     condition: state
>     entity_id: group.all_devices
>     state: home
>   action:
>     service: homeassistant.turn_on
>     entity_id: group.living_room_lights

I dont understand the entity_id section and what I need to have to turn the switch on
I also need to turn it off 1 hour after sunset.

thanks
1 Like

First of all, If I were you, I’d follow the documentation link specified above. It looks like you already know your IP address of your TP-Link switch. I have a bunch of tp-link switches myself, and the configuration I use is

  - platform: tplink
    host: 192.168.1.xxx
    name: Master Bedroom

After you made changes to the configuration.yaml, restart your Home Assistant, and you should see the switches in the UI. Then, click on the hamburger icon on the top left of the screen, under “Developer Tools”, click on “States” icon, and look for entity_id of the switch.
It is usually lower case, and starts with switch.something. Copy that and use that in automations for entity_id.

I have a bunch of tp-link switches, and you can see my configuration here.

to eliminate some confusion…

in HA there are two ways to automate things - scripts and automations. Those two concepts are not interchangeable but they are related.

You are trying to set up an automation. Not a script.

Here is a basic code:

automation:
  - alias: Turn On TP Link Switch
    trigger:
      platform: sun
      event: sunset
      offset: "+01:00:00"
    action:
      service: switch.turn_on
      entity_id: switch.your_tp_link_entity_id_here

many thank both for the very helpful replies, I can turn/off the switch from HA , but its not happy with the automations.yaml

Nov 09 11:09:30 odroid systemd[1]: Started Home Assistant.
Nov 09 11:09:31 odroid hass[8287]: 2018-11-09 11:09:31 ERROR (SyncWorker_0) [homeassistant.util.yaml] while parsing a block collection
Nov 09 11:09:31 odroid hass[8287]: in “/home/odroid/.homeassistant/automations.yaml”, line 2, column 3
Nov 09 11:09:31 odroid hass[8287]: expected , but found ‘’
Nov 09 11:09:31 odroid hass[8287]: in “/home/odroid/.homeassistant/automations.yaml”, line 11, column 4
Nov 09 11:09:31 odroid hass[8287]: 2018-11-09 11:09:31 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/odroid/.homeassistant/configuration.yaml:
Nov 09 11:09:31 odroid hass[8287]: in “/home/odroid/.homeassistant/automations.yaml”, line 2, column 3
Nov 09 11:09:31 odroid hass[8287]: expected , but found ‘’
Nov 09 11:09:31 odroid hass[8287]: in “/home/odroid/.homeassistant/automations.yaml”, line 11, column 4
Nov 09 11:09:31 odroid hass[8287]: Config directory: /home/odroid/.homeassistant

automations.yaml :-

automation:
  - alias: Turn On TP Link Switch
    trigger:
      platform: sun
      event: sunset
      offset: "-01:00:00"
    action:
      service: switch.turn_on
      entity_id: switch.lr_lamp
  - alias: Turn off TP Link Switch    
    trigger:
      platform: sun
      event: sunset
      offset: "+01:30:00"
    action:
      service: switch.turn_off
      entity_id: switch.lr_lamp

the config check shows problems line 2 col 3
but also a bigger problem, its now sulking and port 8123 is closed, so I can get in from the HA
GUI , its a headless unit so no local display, just ssh

Nmap scan report for odroidXU4 (192.168.1.82)
Host is up (0.0072s latency).
Not shown: 995 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
5901/tcp open  vnc-1
8081/tcp open  blackice-icecap
8083/tcp open  us-srv
8085/tcp open  unknown

8080-8087 are camera ports
but 8123 is down , even after a couple of reboots
I dont run a firewall on this SBC as its behind the router which does have one
bit later:-

port 8123 now open again, shutdown the device and left it powered off for a few minutes,
very illogical there should be no difference between a shutdown and power off and a reboot.
but its still having problems with line 2 row 3 and line 11 row 3
which is “-” infront of alias

Configuration invalid

Invalid config for [automation]: [automation] is an invalid option for [automation]. Check: automation->automation. (See /home/odroid/.homeassistant/configuration.yaml, line 108). Please check the docs at https://home-assistant.io/components/automation/

line 108

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml

groups.yaml is empty, should there be some thing in it ?

Your automation.yaml should not contain the line automation: as this is already in the configuration.yaml as explained in the docs

Thanks
the config is now accepted, now just wait untill about 4pm and see if it works or not

Please to say its working :grinning:

Within an automation is it possible to trigger on combination of event data
I also get weather info from dark sky
is it possble to to do
IF darksky cloud coverage is greater than 80% turn on switch at sunset -1hr
else
turn on at sunset -20mins

thanks

Yes, you can use a template trigger.

scroll down till you get to the template trigger section.

Thanks Finity
am I right in my intrepretation
when the value_template is read if not true it will read the next line
which could be another value_template , and so on until a true situation if found
Thanks

1 Like

If I understand what you are asking then the answer is yes.

I don’t have any examples of template triggers to post but generally if you have a trigger like:

trigger: template
value_template: >
  {% if is_state('some_entity', 'some_state') %}
    true
  {% elif is_state('some_entity', 'some_state') %}
    true
  {% else %}
    true
  {% endif %}

it will trigger if any of the if-elif-else conditions are met.

Thanks Infinity
thats what I meant