Help with Scripting - Switch not 'switching'

I would appreciate anyone’s help with the following problem.

My objective is to switch on a USB Drive, then switch on my Plex server using a script.

Here is my script:

   plex_on:
     sequence:
       - service: switch.turn_on
         data: {}
         target:
           entity_id: switch.plex_usb
       - delay: '00:00:02'
       - service: switch.turn_on
         data: {}
         target:
           entity_id: switch.plex_usb
       - delay: '00:00:02'
       - service: switch.turn_on
         data:
           entity_id: switch.plex_server

When invoked, my Plex server turns on OK but the USB drive does not switch on.

If I go into ‘Developer Tools’ in the UI → ‘Services’ and try the following:

   service: switch.turn_on
   data: {}
   target:
     entity_id: switch.plex_usb`

and then Call Service; the USB Drive turns on just fine.

I can’t for the life of me work out what I’m doing wrong and would appreciate any help.

Thanks in advance.

Total guess but the only thing I can see missing from the script is the {} after data for the plex_server line.

Also, any reason why you have service: switch.turn_on twice?

Hi Phil. Thanks for taking the time to reply.

Twice is belt and braces. Sometimes my Lighwave RF switches don’t respond. Although this isn’t the issue here.

The braces are added by the ‘Developer Tools’. They shouldn’t matter (this is the part of the script that actually works). I’ll try adding the braces and see what happens.

For the record I’ve tried the USB control without the data: {}; target: lines so it matches the server control and that doesn’t work either.

Have you tried to use homeassistant.turn_on instead of switch.turn_on? That way HA will use the correct method of switching it on if the normal ‘switch’ method is incorrect.

Hi Stephan. Thanks for your reply.

Yes I have tried this.

Have you checked the script’s debug trace?

Ok I think I got it. The issue is with Lovelace.

Silly mistake. I’m not calling the script! Sort of need to do that I think.

1 Like

Guess that could help :wink:

The number of times I’ve spent hunting down a bug to find it’s something as daft as a missing comma or space is enough to make you face palm!

If you’re not passing any data in the service you can just use:

   plex_on:
     sequence:
       - service: switch.turn_on
         entity_id: switch.plex_usb
       - delay: '00:00:02'
       - service: switch.turn_on
         entity_id: switch.plex_usb
       - delay: '00:00:02'
       - service: switch.turn_on
         entity_id: switch.plex_server