How to switch something off at a certain time and then on again at another time...?

So im running a test system til my proper hardware turns up. Ive got a few devices on the test system to play around with…and, as above i want to switch on an adapter (fish tank light) in the morning and then off at night…how do i do that then? :slight_smile:

You could add a helper (settings > devices > helpers) of type schedule and then use the state of that helper in an automation

Ok - literally dont understand any of that.! ive just found the schedule bit…in there now but no idea how to set it…off to youtube i go…

There are quite a few ways t o do this, Vingerha is right a helper as a schedule is a good way to go, or you could set up trigger ID’s as below.

alias: Toggle-lights-on-and-off
description: ""
trigger:
  - platform: time
    at: "06:00:00"
    id: Power-On
  - platform: time
    at: "23:00:00"
    id: Power-Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Power-On
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.some_switch
      - conditions:
          - condition: trigger
            id: Power-Off
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.some_switch
mode: single

Either way is valid, go to automation have a little play, when you get stuck, come back with some code and we can help you debug it.

2 Likes

Come back with some code? - no idea…no idea what the above is…must confess i was hoping to click on few boxes to switch something on at a certain time…and then off again…!

Maybe i was getting ahead of myself using home assistant…im aware that stuff can be scripted and you could be as granular as you wanted to be but didnt know that was the defacto standard…i must confess i thought to do the very basics…i could literally click on a few boxes to do simple things…if ive got to go on a coding course then maybe its not for me ! :slight_smile:

In this case i wanted to switch a plug on at 8am and off at 9pm every day…does that require me learning to code?

go to settings/automations/create automation
triggers/time choose the time you want
then choose your device and action (device on or off)
create one automation for on and another for off.

make sure your HA system time is correct, including time zone which will depend on your location… otherwise the automations will not trigger as expected.

this is the easiest way.
using helpers or editing code can make this more elegant but it will eventually achieve the same purpose

Hi, make you way over to automations, start with a blank automation, the UI is very click friendly, when you have written some “clicks” look in the top right hand corner at the 3 dots and click edit in YAML it will show you the code behind those boxes

Good luck

The above is what is stored in the automations. Automations can be clicked together, but that is hard to put here. So this is something you can cut and paste. Although this particular example is not easily clicked, it can be done pretty simple using the user interface.

But, really no offense meant at all, maybe Home Assistant is not the best system for you if this all scares you. Particularly if this simple scenario is already hard to figure out on your own. Maybe Homey is something that you can try out for free if that is something you might like - and maybe upgrade to Homey Pro if you do? That is all click, no code. Home Assistant is working towards that, but the harder stuff often does require editing files, and all the answers you get here are often exactly like the one you got.

No - no offense taken…ironically i work in IT but i dont go anywhere near coding in any shape way or form…ive not got the head for it…it doesnt scare me but at the same time ive no idea how to write code…

Great - this is what i wanted…ill start here…

Ok – so ive got in the trigger option…
Trigger
Button Fish Tank Identify has been pressed (what does that mean)?
or (Device offline) - what does that mean…? (i dont want to press anything…i want it, to do the “pressing” as it were!

The 2 description of the 2 states dont relate to what im trying to do…

Really sorry to sound so thick but ironcally getting the whole setup and connected seemed a breeze (proxmox, adding in the ConbeeII etc etc) to actually using it! :slight_smile:

90% of what i did with the old system was switching stuff on and off at certain times…the plan was to get that all in place, then, maybe get a bit more clever with it afterwards…

you need to find your light device and then the action would be to turn it on or off
you can search for light in the device field if you know the name of the light you want to use

A trigger is something that needs to happen to start an action. There’s nothing happening in your fish tank just yet. So you shouldn’t be looking at the fish tank for the trigger (that is for the action bit). What you want is for a time to trigger this thing.

So for the trigger type choose time. The dialog will show you the rest.

Then the fish tank is where the action should be. Here comes a bit cunfusing part. Though you can select a device as the action, and then what to do with it, this is often not the best way - especially if you need to change things later on.

Home assistant is big on services that can act on devices or entities belonging to devices. So choose Call Service for the action. Then choose the service that can do the things you need, e.g. homeassistant.turn_on (or light.turn_on, if it is a light this can do more light specific stuff).

From there you can choose the entities that you want to act on ( again, confusing, better not pick device). The entity is the fish tank. But you can pick a lot more entities here to go on at the same time if you wish.

There. You got the basics.

Oh… and when you do it this way, it is easier to create two automations. One for one and one for off.

I found this guy was a big help in my early days… Smart Home Junkie

Start with a plan, draw it out if necessary, I did, then step through each step, a device can be the lights or a switch, just take you time and you will get there, but a plan of what you want the automation to do is always a a good starting point.

Thanks for all the help/suggestions…we all have to start somewhere…im hoping the more i use it…the more stuff becomes second nature…i really would like to get better with it…at its very basic just the action of switching off said fish tank light is faster and more instant than the oem system…as i say and say again…my apologies for sounding so thick as to you guys this is all second nature remedial stuff…!

I found this guy was a big help in my early days… Smart Home Junkie

Start with a plan, draw it out if necessary, I did, then step through each step, a device can be the lights or a switch, just take you time and you will get there, but a plan of what you want the automation to do is always a a good starting point.

Many thanks…(ive seen him before but just subs to his channel)

Hi - been off doing other chores this afternoon…got a couple of hours to spare…so my fish tank light…is just the light (realizing i have to be more exact) - its an aurora Zigbee adapter which is powering the light…which has been added to home assistant…i cant see anything in the services that looks like a zigbee aurora adapter…(i think)

Success! - think ive managed to do that…! (thanks very much Edwin) so i have one timer set…thanks for putting up with me…im really sorry to say theres gonna be a lot more questions coming…!

1 Like

I had not realized the Schedule Helper was available. It took a bit to figure out how to make my device turn on and off appropriately.

I found another post that showed using template code but I was able to put this together in the UI using Add Building Block to add the Choose cases.

Thought I would share for others looking for how to do this type of thing.

alias: HRV schedule
description: Turn on the HRV at night and off during the day based upon a Schedule helper
trigger:
  - platform: state
    entity_id:
      - schedule.schedule_hrv
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: schedule.schedule_hrv
            state: "on"
        sequence:
          - type: turn_on
            device_id: a32da1afc2a088e334109ca55eac9ac4
            entity_id: e3db2d12f85527c59b466cc51fbe20cd
            domain: switch
      - conditions:
          - condition: state
            entity_id: schedule.schedule_hrv
            state: "off"
        sequence:
          - type: turn_off
            device_id: a32da1afc2a088e334109ca55eac9ac4
            entity_id: e3db2d12f85527c59b466cc51fbe20cd
            domain: switch
mode: single

This was SUPER helpful!! Thank you :slight_smile:

Here’s my Pool Pump Automation to deal with Time of Use rates in my area. Maybe not the best way to do it, but worked for me. My first attempt was setting the TOU rate as a variable on the pump and using that, but I want a couple hours during mid peak times, not the whole rate time and delay’s weren’t going to work well with HASS restarts and updates etc…

alias: Pool Pump Automation
description: ""
trigger:
  - platform: time
    at: "09:00:00"
    id: Morning-On
  - platform: time
    at: "11:00:00"
    id: Morning-Off
  - platform: time
    at: "17:00:00"
    id: Afternoon-On
  - platform: time
    at: "19:00:00"
    id: Afternoon-Off
  - platform: time
    at: "23:00:00"
    id: Night-On
  - platform: time
    at: "07:00:00"
    id: Night-Off
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Morning-On
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
          - service: notify.mobile_app_nates_iphone
            metadata: {}
            data:
              message: Turned On!
              title: Pool Pump
      - conditions:
          - condition: trigger
            id: Morning-Off
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
      - conditions:
          - condition: trigger
            id: Afternoon-On
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
          - service: notify.mobile_app_nates_iphone
            metadata: {}
            data:
              message: Turned On!
              title: Pool Pump
      - conditions:
          - condition: trigger
            id: Afternoon-Off
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
      - conditions:
          - condition: trigger
            id: Night-On
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
      - conditions:
          - condition: trigger
            id: Night-Off
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.pool_pump_switch
mode: single