Smart Plug Automation

I am new to Home assistant and I am migrating from using grid connect devices to Zigbee devices in Home assistant.
I have bought 2 Zigbee smart plugs to control garden fairy lights and spot lights and I am trying to write an automation to turn the lights on run for a specified time and turn off . I can get the lights to turn on but when i have the turn request in the automation they turn on and off .
Is there a simple automation out there to help me get started.
Thanking you in anticipation.
Graham

On automation

triggers:
  - platform: time
    at: "18:00"
actions:
  - action: switch.turn_on
    target:
      entity_id: 
        - switch.fairy_lights
        - switch.spot_lights

Of autaomtion

triggers:
  - platform: time
    at: "23:30"
actions:
  - action: switch.turn_off
    target:
      entity_id: 
        - switch.fairy_lights
        - switch.spot_lights

Alternative on automation trigger:

    - trigger: sun
      event: sunset
      offset: "00:30:00" # 30 minutes after sunset (optional)

More:

and if you want to make it conditional on something else:

alias: fairy lights
description: "turn fairy lights on at 20:00 and off at 06:00"
triggers:
  - trigger: time
    at: "20:00:00"
    id: Lights on
  - trigger: time
    at: "06:00:00"
    id: Lights off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Lights on
        sequence:
          - action: switch.turn_on
            target:
              entity_id: switch.zigbee_fairy_lights
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Lights off
        sequence:
          - action: switch.turn_off
            target:
              entity_id: switch.zigbee_fairy_lights
            data: {}
mode: single

Thanks Tom for your response.
I have processed the automation the switch turns on and off immeadiately.
I dont know if I have a faulty switch.

Thanks Krivatri for your response.
I have processed the automation the switch turns on and off immeadiately.
I dont know if I have a faulty switch.
[/Thanks Tom for your response.
I have processed the automation the switch turns on and off immeadiately.
I dont know if I have a faulty switch.]

ok, strange.
you could try to make a helper switch and replace the switch.zigbee part in your automation with the helper switch for debugging.
also if it’s possible to provide your code so we can check for bugs?
how did you wire your zigbee? do you have a schematic?

Thanks Krivatri for your response.
The plugs were purchased from amazon.
They will work if I disable half the program.
They can turn on if the off commands are disabled.
They can turn if if I have manually turned on the plug disabled the on command and execute the off command.
How do I copy my automation to share with you.

copy the yaml code from your automation and paste in your reply between the dots, example below.

you can find the code as follows:

alias: Smart plug automation
description: “”
triggers:

  • trigger: time
    at: “17:09:00”
  • trigger: time
    at: “17:15:00”
    conditions:
    actions:
  • action: switch.turn_on
    metadata: {}
    data: {}
    target:
    device_id: 7e6c915d70c829234a83d55993b3bbc0
  • action: switch.turn_off
    metadata: {}
    data: {}
    target:
    device_id: 7e6c915d70c829234a83d55993b3bbc0
    mode: single

ok, your code is wrong.
your smart plug will turn on and off at 17:09 and same at 17:15.
you need to give each trigger an id and then use the id in your action.

your code should be like this:

alias: Smart plug automation
description: ""
triggers:
  - trigger: time
    at: "17:09:00"
    id: Lights on
  - trigger: time
    at: "17:15:00"
    id: Lights off
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Lights on
        sequence:
          - action: switch.turn_on
            target:
              device_id: 7e6c915d70c829234a83d55993b3bbc0
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Lights off
        sequence:
          - action: switch.turn_off
            target:
              device_id: 7e6c915d70c829234a83d55993b3bbc0
            data: {}
mode: single

f6be36681e0da431418ec7781fb6c62712941803

And see Krivatri’s answer.

Thanks Krivatri for your assistance
Still having issues I have uploaded my latest version
alias: New automation
description: “”
triggers:

  • trigger: time
    at: “15:36:00”
    id: Switch On
  • trigger: time
    at: “13:38:00”
    id: Switch Off
    conditions:
  • condition: trigger
    id:
    • Switch On
  • condition: trigger
    id:
    • Switch Off
      actions:
  • action: switch.turn_on
    metadata: {}
    data: {}
    target:
    device_id: 9fd4faff70d4e83916907f1c67ec16f4
  • action: switch.turn_off
    metadata: {}
    data: {}
    target:
    device_id: 9fd4faff70d4e83916907f1c67ec16f4
    mode: single

Please format your code correct. See example above.

that won’t work either, please replace your automation code with mine and start from there.

Thanks Krivati
Are you able to provide a copy of you automation.

I did, the code I provided is the complete automation you need.

if your not sure how to copy the code into your automation, here is how:

first edit your automation and go to the 3 dots at the top right, click on it and select “Edit in YAML”.
select all and delete your code, then paste my code and save.
finally go to developer tools and reload the automations.

Finally it works.
Thanks for your help Krivatri .
It has been a steep learning curve.

You’re welcome , we all had to go through these first steps.