First automation, UI integration help with wake on lan and smat plug

I finally flashed my 2 first smart plug with tasmota, yay!

I plugged my computer on one and I’m trying to make this smarter. What confuses me is the many moving independant pieces.

I have:

  • switch.tasmota_plug_2 (autodiscovered from ha)
  • switch.my_computer - which is a wake on lan switch, the Turn Off option is set with a shell script to turn off my computer
- platform: wake_on_lan
  mac: "22:22:22:22:22:22"
  host: 192.168.0.2
  broadcast_address: 192.168.0.255
  name: My computer
  turn_off:
    service: shell_command.my_computer_turn_off

shell_command:
my_computer_suspend: 'ssh [email protected] sudo pm-suspend'
my_computer_turn_off: 'ssh [email protected] sudo shutdown +1 "Shutting down in 1 minutes."'

I currently have 2 automations: (In GUI)

Title: Wake my PC when SmartPlug 2 is turned on
Trigger:
  - Device: Tasmota Plug 2
    Trigger: Tasmota Plug 2 turned on
    Time: 00:00:10
Condition:
  State: switch.my_computer is off
Action:
  Call service: switch.turn_on switch.my_computer (wake on lan)

The second one:

Title: turn off smartplug when my computer is powered down
Trigger:
  State for switch.my_computer from on to off for 00:01:00
Condition:
  State swtich.my_computer is off (wake on lan ping)
  AND sensor.tasmota_plug_2_energy_power < 20 (smart plug uses less than 20 watts, just in case there is something wrong with my ethernet cable, might try to guess if computer is in suspend mode or shutdown completely)

Action: Device Tasmota plug 2 turn off

My issue comes when I want to use those in lovelace.

I’d like a switch, than when I turn it on, it will turn on the smart plug then wake on lan (switch.my_computer)
When I click to turn the switch off I want to call shell_command.my_computer_turnoff then the automation should turn the power off from the smart plug after x minutes.

Since the switch on and switch off should cal different thing, I’m not quite sure how I should do this and if my automation make sense (the smart plugs are my first 2 connected things that I can interact with). I also want to avoid accidentally turning off the plug while my computer is running.

I currently have a card in lovelace with a list of devices and if they are connected to the network or not.
image
I wonder if it would be possible to show Connected (to the network), TOn (power from outlet but no internet), Powering up, powering down, Off (smart plug is off), etc. I think it would help to debug in case of problems too, but I’m so confused with all the moving parts. Sensor here, sensor there, template in another file for another thing and somehow they need to all work - and don’t change any names :laughing:

Thanks community! :beers:

Create a template switch

  - platform: template
    switches:
      mycomputer:
        value_template: "{{ is_state('binary_sensor.pingcomputer', 'on') }}"
        turn_on:
          - service:switch.turn_on
            data:
              entity_id : Tasmota Plug 2
          - service: switch.turn_on
            data:
              entity_id : switch.my_computer 
        turn_off:
          - service:switch.turn_off
            data:
              entity_id : switch.my_computer 
          -  delay: 00:01:00
          - service: switch.turn_off
            data:
              entity_id : Tasmota Plug 2

You will still need to replace the binary_sensor.pingcomputer, Tasmota Plug 2 and switch.my_computer
with the correct identities

1 Like