#Automatically adjust automations based off reply from actionable notification

52 messages · Page 1 of 1 (latest)

torn geyser
#

Hello,
I often go to bed at very different times, so I would like to have HA send me an actionable notification at 10 PM that I can reply to with the time I have my alarm set to (because no alarm apps have an api I can grab that from). I want to use the time that I enter to automatically change some automations I have set up (turn up the lights, run command from Google home, etc) so that they come on earlier or later depending on when my alarm is set. I have been messing around with a few different templates but nothing has been seeming to work. If anyone can give me some guidance I would appreciate it.

round horizon
#

Hey, @torn geyser you may adjust your automations accordingly, based on the response

torn geyser
round horizon
#

ofc you have input_text entity right?

#

you can create an sutomation triggers a notification at 10 pm

#

by handling yaml file

#

And next you can create another automation to handle the response form the actionable noti

#

not make sense?

#

shall I share sample code?

torn geyser
#

I already have the automation to send the notification at 10. The only issue is trying to automatically adjust my morning automations based off the time input from the reply

round horizon
#

See. then you need to focus on capturing the alamtime imput and using it to adjust ur morning automations

torn geyser
#

Exactly. If you know how I can do that, that is what I am looking for.

round horizon
#

hang on plz

#

Let's see u r using notification service that allows a reply

automation:
  - alias: Set Alarm Time
    trigger:
      platform: event
      event_type: telegram_message_received
    condition:
      - condition: template
        value_template: "{{ trigger.event.data.message is not none }}"
    action:
      - service: input_text.set_value
        data:
          entity_id: input_text.alarm_time
          value: "{{ trigger.event.data.message }}"
#

you can adjust event_type for your notification service

#

Now, create another automation that triggers when input_text.alarm_time change

#

here is example automation for adjusting morning automations

automation:
  - alias: Adjust Morning Automations
    trigger:
      platform: state
      entity_id: input_text.alarm_time
    action:
      - service: light.turn_on  # Example action
        data_template:
          entity_id: light.your_light_entity
          brightness_pct: >
            {% set alarm_time = states('input_text.alarm_time') %}
            {% set alarm_hour = alarm_time.split(':')[0] | int %}
            {% set alarm_minute = alarm_time.split(':')[1] | int %}

            {% if alarm_hour < 6 %}
              100  # Bright light for early alarms
            {% elif alarm_hour >= 6 and alarm_hour < 8 %}
              75   # Slightly dim for mid-morning
            {% else %}
              50   # Dim light for late mornings
            {% endif %}
#

Btw, you should adapt the entity IDs and logic as necessary for your situation

torn geyser
#

The first part works great. Thank you. I was hoping for something a little different for the second part, though. I have an automation that slowly turns on the lights over 15 minutes and an automation that plays the forecast through my Google nest. What I am hoping to change, is when those automations trigger, not the action. For example, if I reply with alarm time of 6:45, start turning on lights at 6:30 with a transition from 0 to 100% over 15 minutes. The next one would be, if I reply with alarm time of 6:45, send a command to my Google nest to play the weather forecast at 7 AM. Basically, light automation 15 minutes before alarm and Google nest automation 15 minutes after alarm

round horizon
#

sorry for late answer.

#

Ive just checkd ur msg.

#

you can mention me with ur msg like @round horizon

#

let me see

torn geyser
#

@round horizon It seems the way to do this would be to set the trigger to time based off value of a date/time helper. I just need to find a way to get my reply to be entered in to my time helper because the first code you sent me works fine for a input_text but not for input_datetime.set_datetime

round horizon
#

umm

#

let me think

#

give it a try like this.

#

you can convert alarmtime you set into the input_datetime helper and then trigger your automation based on that time.

#

so first, create an input_datetime helper to store the alarm time

#

maybe I am sure you re able to do this by urself

torn geyser
#

The actionable notification is sent to my iOS device. When I give it a reply of 6:45, that value does not get entered in to the datetime helper. I need to find a way to get it to enter in, that seems to be the most simple solution @round horizon

round horizon
#

yeah

#

so now have you defined input_datetime in ur config yaml file?

torn geyser
#

I already created a helper for that some time ago. I'm just trying to get the reply from my iOS device to populate into the helper. It will populate into an input_text helper but not an input_datetime helper

#

If I'm correct, the text sent back from the reply is a string but it needs to be a timestamp, right?

round horizon
#

correct

torn geyser
#

I'm not sure how to convert that

round horizon
#

now update the automation like this.

automation:
  - alias: Set Alarm Time from Telegram
    trigger:
      platform: event
      event_type: telegram_message_received
    condition:
      - condition: template
        value_template: "{{ trigger.event.data.message is not none }}"
    action:
      - service: input_datetime.set_datetime
        data:
          entity_id: input_datetime.alarm_time
          time: >
            {% set alarm_time = trigger.event.data.message %}
            {% if alarm_time %}
              {% set parts = alarm_time.split(':') %}
              {% if parts | length == 2 %}
                {{ parts[0].zfill(2) }}:{{ parts[1].zfill(2) }}:00
              {% else %}
                "00:00:00"  # Default to 00:00:00 if the message is incorrectly formatted
              {% endif %}
            {% else %}
              "00:00:00"
            {% endif %}
#

Now, update the second one to adjust morning routin based on the input_datetime entity

#

hang on for now

#

I will try Lights Automation -> 15 mins before alarm

#

Okay?

#

if you have an idea, let me know

torn geyser
#

okay

#

Thank you for the help

round horizon
#

for instance, wanna turn on the lights 15 mins before alarm and trigger Google Nest 15 mins after alarm

round horizon
#

wait a min

#

yeah. have done

#

btw can I send it as DM?

torn geyser
#

yeah