Turn on lights at a set time

hey guys,

i´m trying to set an automation that turns on a light at a set time. kind of as an alarmclock.
also i´d like to change the time using a button-card.

for example 1 button-card that sets the time to 4:30am on weekdays and another one that sets the time to 8am.

is that possible?

Yes, this is definitely possible, however I don’t understand how you want to do this with a button-card? A button-card gives you what it says, a button. I suggest creating one input_datetime for the weekend and one for the weekdays. Then create two automations that will turn on the light if the current time is equal to the input_datetime.

since i need to change it on a weekly base (and want to turn it off for weekends) i‘d like to set the time with a button-card.

Personally, I built a date_dayoftheweek sensor, as well as a date_weekday sensor and use them for automation conditions all the time.

    date_dayoftheweek:
      value_template: >
        {% set ct = states('sensor.date_time') %}
        {% set ct = as_timestamp(strptime(ct,'%Y-%m-%d, %H:%M')) %}
        {{ ct | timestamp_custom("%A") }}

    date_weekday:
      value_template: >
        {% if is_state('sensor.date_dayoftheweek', 'Saturday') %} off
        {% elif is_state('sensor.date_dayoftheweek', 'Sunday') %} off
        {% else %} on
        {% endif %}

Not 100% sure your use-case; however.

1 Like

if you use node-red for automation, you can simply use inject node to trigger it.

Sorry, I still don’t get it.

How do you intend to set the time with a button??
Below is a picture of some buttons created with the button-card. The button can be on or off.

image

What you probably want is an input_datetime as I suggested and a toggle to turn it on/off.
Something like the example below.

image

3 Likes

since i usualy use my mobilephone for hass.io i did the whole UI using button-card.
want to do a popup-card to set the time, like i did with my thermostats (2nd pic)

so for example 3 buttons:

  1. 6am
  2. 8am
  3. off

what i just did:

set an automation:

- id: '1580491150790'
  alias: test
  description: ''
  trigger:
  - at: 04:25
    platform: time
  condition: []
  action:
  - entity_id: light.gang
    service: light.turn_on

and did a button for it to turn it on or off:

type: 'custom:button-card'
template: button_card
entity: automation.test
icon: 'mdi:alarm'
name: Frühschicht

lets see if this works

Ah now I finally understand! How about putting an input datetime inside the popup card then? Would make it more flexible.

Nice. I had a typo but was using the same solution as you for dayoftheweek (although without using variables - I might adopt that to make it easier to read).

If you aren’t aware, it’d be easy to invert Workday - Home Assistant

Many times there’s more than one way to skin-a-cat in HA.

Personally - I’ve learned that if it works, don’t mess with it. There might be a cleaner / better / quicker / different way - but usually that involves spending more time tinkering to get back to the exact same spot you were already at…

Hi,

can you share the code for this example " Slow Cooker" please.

tks

I would also like to see the code for the “Slow Cooker” sample.
Thank you :pray: