Creating a alarm clock

from automation.yaml
Publish the alarm time hours when it has changed.

 - alias: MQTT TimeSlider Hours
   trigger:
     - platform: state
       entity_id: input_number.alarmtimehrs
   action:
     - service: mqtt.publish
       data_template:
         topic: "cmnd/MQTTSliderSaveHrs"
         retain: true
         payload_template: '{{states.input_number.alarmtime.state | int}}' <------ this may need to be changed or you may be able to use the new input.date_time - doing it this way you would need to do the same for the minutes

The following sets the Alarm time hours from the MQTT that is received when HA resets…

 - alias: 'Set Alarmtime Hours from MQTT'
   trigger:
     - platform: mqtt
       topic: cmnd/MQTTSliderSaveHrs
   action:
     - service: input_number.set_value
       data_template:
         entity_id: input_number.alarmtimehrs
         value: '{{ trigger.payload}}'

You will have to modify this to your own use case.

I don’t know why the other way (that I showed above) would not work except that you would need to change every use of input_slider to input_number in the yaml and the python code.

input_slider has changed to input_number in version 0.55. I have updated the code in my github to reflect that.

Don’t worry. The value will not lost after restart.

I am using this: https://www.youtube.com/watch?v=qJ8ZoJuuZVA
Works great :slight_smile:

@masterkenobi i follow your alarm on github.
I use hass.io but when i restart home assistant i lost the values hour and minutos. The values not stored. I think the solution is what @keithh666 said.

@keithh666 i tried your example but not works.
The values of hours and minutes are reseted when i restart home assistant :frowning:

Sorry. You need to remove the initial from the input_boolean and input_number. I have updated the codes. It should remember the value now.

You can use something like this Chromecast Radio with station and player selection and create an automation for when the alarm clock goes start playing one of the radios

@masterkenobi thanks mate.
now it Works, but with one BIG problem.
if you delete home-assistant.log and home-assistant_v2.db all the sliders values are deleted and not stored.
@dale3h had the big solution for this, using MQTT.

the config is:

inside of customize.yaml

automation.persistence_publish:
  friendly_name: "Persistence Publish"
automation.persistence_subscribe_binary:
  friendly_name: "Persistence Subscribe (Binary)"
automation.persistence_subscribe_select_option:
  friendly_name: "Persistence Subscribe (Select Option)"
automation.persistence_subscribe_select_value:
  friendly_name: "Persistence from MQTT (Select Value)"
#inputes
input_number.alarmhour:
  persistent: true
input_number.alarmminutes:
  persistent: true

inside of automations.yaml

- alias: persistence_publish
  initial_state: 'on'
  hide_entity: true
  trigger:
    - platform: event
      event_type: state_changed
  condition:
    - condition: template
      value_template: "{{ trigger.event.data is not none }}"
    - condition: template
      value_template: "{{ trigger.event.data.new_state is not none }}"
    - condition: template
      value_template: "{{ trigger.event.data.new_state.attributes is not none }}"
    - condition: template
      value_template: "{{ trigger.event.data.new_state.attributes.persistent|default(false, true) }}"
    - condition: template
      value_template: "{{ trigger.event.data.old_state is not none }}"
    - condition: template
      value_template: "{{ trigger.event.data.new_state.state != trigger.event.data.old_state.state }}"
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'automation' }}"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'input_boolean' }}"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'input_select' }}"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'input_number' }}"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'light' }}"
        - condition: template
          value_template: "{{ trigger.event.data.entity_id.split('.')[0] == 'switch' }}"
  action:
    - service: mqtt.publish
      data_template:
        topic: "home-assistant/{{ trigger.event.data.entity_id|replace('.', '/') }}"
        payload: "{{ trigger.event.data.new_state.state }}"
        retain: true

## Persistent Subscriptions
- alias: persistence_subscribe_binary
  initial_state: 'on'
  hide_entity: true
  trigger:
    - platform: mqtt
      topic: home-assistant/automation/+
    - platform: mqtt
      topic: home-assistant/input_boolean/+
    - platform: mqtt
      topic: home-assistant/light/+
    - platform: mqtt
      topic: home-assistant/switch/+
  condition: &subscribe_condition
    - condition: template
      value_template: "{{ ((states[trigger.topic.split('/')[1]][trigger.topic.split('/')[2]]|default).attributes|default).persistent|default(false, true) }}"
    - condition: template
      value_template: "{{ not is_state(trigger.topic|replace('home-assistant/', '')|replace('/', '.'), trigger.payload) }}"
  action: &subscribe_action
    - service_template: "{{ trigger.topic.split('/')[1] }}.turn_{{ trigger.payload|lower }}"
      data_template:
        entity_id: "{{ trigger.topic|replace('home-assistant/', '')|replace('/', '.') }}"

##
- alias: persistence_subscribe_select_option
  initial_state: 'on'
  hide_entity: true
  trigger:
    - platform: mqtt
      topic: home-assistant/input_select/+
  condition: *subscribe_condition
  action:
    - service_template: "{{ trigger.topic.split('/')[1] }}.select_option"
      data_template:
        entity_id: "{{ trigger.topic|replace('home-assistant/', '')|replace('/', '.') }}"
        option: "{{ trigger.payload }}"

##
- alias: persistence_subscribe_select_value
  initial_state: 'on'
  hide_entity: true
  trigger:
    - platform: mqtt
      topic: home-assistant/input_number/+
  condition: *subscribe_condition
  action:
    - service_template: "{{ trigger.topic.split('/')[1] }}.set_value"
      data_template:
        entity_id: "{{ trigger.topic|replace('home-assistant/', '')|replace('/', '.') }}"
        value: "{{ trigger.payload }}"

now you can update your GitHub :wink: it Works like a charm.
for all the peope that want to use this is a best solution, because all data is saved via MQTT

*** this method Works with: automation, input_boolean, input_select, input_number, light e switch***

If you delete the home-assistant_v2.db, you delete the history database. previous states of every entities will be gone.

Anyway, I never had to delete the db. I am using MYSQL database hosted on another machine.

1 Like

Any thoughts or help please? :slight_smile:

I don’t need any input selectors in the frontend nor do I need different radio stations.
I just want to use voice input for setting up the alarm.
Here is my first approach but that one is missing a few things: Set up a radio alarm timer with IFTTT
How can I accomplish it?

Hi,

Maybe not the right place to post this… But I will try anyway :slight_smile:

I need some help with the creation of a car heater function (Living in Sweden) and winter is coming :wink:

I have an outside temp sensor and a switch to connect to the heater in my car.

If the temperature is < 10 i want the heater to start 30 minutes before the actual time to leave.
If the temperature is < 0 i want the heater to start 60 minutes before the actual time to leave.
If the temperature is < -10 i want the heater to start 90 minutes before the actual time to leave.

I also want the heater to run for 30 min after the actual time to leave (if I am late).
It would also be great if it could be started/stopped manually.

I have searched the forum for this, but with no luck…

This is way off my skills, so I trust in you guys :pray:

Hi,

You must create differents automations, depending on the conditions that you want.

Maybe create new topic ask for help.

Hi,

Yes I created a new topic in the forum. Thanks for the advice :slight_smile:

Hi @seriksson,

Can you put the link, just to read, understant what you want and try to help you.

thanks,

@garvarma, Here it is: Car Heater (winter is coming) need coding help!

… to change country? :smiley:

1 Like

@anon35356645
Haha, Me too :wink:

Creating sunrise alarm clock…

My goal is to have “sunrise” alarm clocks using smart led bulbs for all 6 of us in my family. So, there’s a lot of variables involved - different lights at different times on different days. And, eventually the reverse where some lights get gradually dimmer at night (for the younger kids)

When I first looked into smart lights I looked into MiLights and really liked what the guy in this link did:
http://iqjar.com/jar/wake-up-gently-to-gradually-increasing-light/
He made a function (script? automation?) for the the gradual light increase, then he calls it at set times using Cron. However in my case I would need to pass a parameter of which light I was referring too.

I decided not to go the MiLight route because I didn’t like the four zone limit, which brought me to Home Assistant. :slight_smile:

I think from reading this page I can figure out how to assign the times & days. But is it possible to create something (script? automation? effect?) to contain how to do the sunrise effect then call it at a specific time and pass a parameter of which light?

1 Like

Ok, so it looks like maybe I can do this with a Python script?