Giter Site home page Giter Site logo

hassalarm's Introduction

hassalarm

Android app for integration with Hass.io / Home Assistant as an input_datetime for the next scheduled alarm on the device.

Expect that alarm clocks schedule alarms properly which will trigger the system wide ACTION_NEXT_ALARM_CLOCK_CHANGED. Once that happen, a call to your Hass.io instance will happen within an hour, given that there is an Internet connection. On failure, the Android OS will retry later.

Home Assistant setup

  1. Require Home Assistant 2020.12.1 or later.
  2. Add a input_datetime with both date and time in your configuration.yaml
input_datetime:
  next_alarm:
    name: Next scheduled alarm
    has_date: true
    has_time: true
  1. Add a time sensor in your configuration.yaml:
sensor:
- platform: time_date
  display_options:
    - 'date_time'
  1. If you want the value to persist on Home Assistant restarts, enable the History and Recorder components.
  2. Add some automation for your new input:
automation:
  trigger:
    platform: template
    value_template: "{{ states('sensor.date_time') == (state_attr('input_datetime.next_alarm', 'timestamp') | int | timestamp_custom('%Y-%m-%d, %H:%M', True)) }}"
  action:
    service: light.turn_on
    entity_id: light.bedroom

Or if you want to trigger an automation five minutes before the alarm will go off:

  automation:
    trigger:
      platform: template
      value_template: "{{ ((as_timestamp(states('sensor.date_time').replace(',','')) | int) + 5*60) == (state_attr('input_datetime.next_alarm', 'timestamp') | int)  }}"

    action:
      service: light.turn_on
      entity_id: light.bedroom

Webhook support

HassAlarm supports updates through a webhook. This requires some setup on the Home Assistant side, but it greatly reduces the permissions the app has in Home Assistant. To use a webhook for HassAlarm updates, you can use the automation below and adapt it as necessary. Note that your webhook ID should be hard to guess.

This automation will update ànd set the input_datetime for the entity ID specified in the app. Then you can use the input_datetime sensor in your automations as in the example above.

automation:
  trigger:
    platform: webhook
    webhook_id: <your webhook id>
  action:
    service: input_datetime.set_datetime
    data_template:
      entity_id: "{{ trigger.json.entity_id }}"
      timestamp: "{{ trigger.json.timestamp }}"

App usage

  1. Install via Google Play Store or clone the repo and build the app: ./gradlew installDebug
  2. Create a long lived token on your profile or a webhook automation in Home Assistant.
  3. Open the app and setup your hostname, longed live token and input_datetime entity ID: input_datetime.next_alarm
  4. Schedule an alarm in any of your alarm apps

Once your device have a network connection, it should eventually do a call to the Hass.io API and your input_datetime should be set.

Troubleshooting

  1. Make sure the app is allowed to run in the background (e.g. start a sync job), read more here: https://support.google.com/pixelphone/thread/6068458?hl=en (thanks @Hooolm)
  2. Make sure to use a fairly recent version of Home Assistant, 2020.12.1 or later. 2020.12.0 have bugs with input_datetime
  3. If the time reported in Home Assistant is off by hours or minutes, first try using The stock Google Alarm Clock. There are known bugs with the Samsung [1] and Xiaomi [2][3] alarm clock, and probably others. If there are still issues when using the Google Alarm Clock, please open a issue here on GitHub.

Build status

Build Status

hassalarm's People

Contributors

eifinger avatar fixxcz avatar izzysoft avatar johboh avatar mvn23 avatar sjohboh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hassalarm's Issues

Incorrect timestamp

I believe there is a bug, but I'm unsure if it is due to Hassalarm or HA.

I have two sensors: input_datetime.next_alarm - through Hassalarm -, and sensor.abelphone_next_alarm - through the app. They both sync my alarm time with HA and the times match, see pic 1.

However, I believe there is an error when converting it to a timestamp (see pic 2), they lead to different values. The required value is 7:05 (UTC), which for me is 8:05 (CET, Paris).
Hassalarm converted to timestamp and back reports: 1608277500 Is equivalent to: 12/18/2020 @ 7:45am (UTC)
App alarm converted to timestamp and back reports: 1608275100 Is equivalent to: 12/18/2020 @ 7:05am (UTC)

My first guess would be that since Hassalarm does not add the timezone, that should lead to mistakes. However this does not match with an offset of 40 minutes. Would you have an idea how this is caused?

1
image
2
image (1)

Manage multiple device ?

Hi,

First thanks you for your app, this is the best and easiest way to sync my alarm with HA. With 1 device it work great but... any solution to use it with more than one device ? Like this:

  • input_datetime.user1_next_alarm
  • input_datetime.user2_next_alarm

It would be great, and with this feature we can make automation depending the user.

Benjamin

Can't get automation to trigger

Hi,

I tried your app and intergtration, however, i ran into some problems.

In Developer Tools -> States i can see the next alarm on my phone (correct value)
image

When entering the following test code in Developer tools -> Templates, i get empty string (a date in 1970):

{ states('sensor.date_time') }}
{{ state_attr('input_datetime.next_alarm', 'timestamp') }}
{{ state_attr('input_datetime.next_alarm', 'timestamp') | int | timestamp_custom('%Y-%m-%d, %H:%M', True) }}

I get this output:
image

Why does the input_datetime.next_alarm have the correct value in the states menu, but no value when testing the template? (neither when used in a automation)

Best regards,
Martin

Can't get to automatically trigger

The app broadcasts fine and hass updates the next alarm. I can manually trigger the automation, and it does what it's supposed to. But the value template does not seem to work?

I implemented it from the UI and edited until it looked correct (for easier editing in the future)
Here it is:

image

Restarted hass without luck.

crash if Google Alarm Clock is usd on huawei ANE-LX1

i'm not able to submit an alarm scheduled if the schedule comes from google alarm clock app. when i tap the homeassalarm's icon the app close immediately but it is still running.
the only way to interact with the application is to disable the scheduled alarms in google alarm clock.

let me know what can i do to help in solving the issue

Connection failed - Trust anchor not found

Hi,

First of all, thanks for this great app. It has been working flawlessly for me before, however since I moved my Home Assistant (Hass.io) to my Synology NAS it is not working anymore.

I created a new Long-Lived Access Token and updated the server address accordingly but got the following error:

Using long lived token
Entity ID is of type input_datetime
Request: POST /api/services/input_datetime/set_datetime

Request headers: Authorization: Bearer

Request body: {"datetime":"2020-04-16 08:00:00","entity_id":"input_datetime.next_alarm_daan"}

Failure: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

The connection itself is working and also the Long-Lived Access Token works in Tasker.

Any idea what might be the problem here?

Thank you in advance for your help!

Kind regards,
Daniel

Entity not available after HA restart

After restarting HA it loses the sensor identity of hassalarm until I either turn my alarm on/off, change the time or start the hassalarm app and tap 'save and test'.

As I'm often tinkering with the system after my gf's gone to bed and has set her alarm, this presents a problem.

Is there any way to tackle this?

Sync the alarm's enabledness

What's the expected behaviour if I disable all alarms on my phone? If I go into Hassalarm, it says "No next alarm scheduled", but it doesn't perform any successful requests to Home Assistant while in this state. So in Home Assistant, the alarm time stays as it was, as though I hadn't disabled it.

I'm not sure what the sensible thing to do here really is. Perhaps set the alarm time to an arbitrary date in the past or far future? Seems a bit inelegant, but would be an improvement on the current behaviour.

automation

Thanks for the very useful app. Do you have suggestions to easily automate the synchronization, in case I forget to start up the app?

e.g.

  • would there be a way of not having to push the button "Save and test connection" to synchronize everything? This would allow to start up the app with apps like MacroDroid or Tasker (e.g. every time I get connected to my wifi network, the sync occurs).
  • or would there be relevant parts of the app that could be easily added to a script which can be automatically called?

thanks!

Version 1.26 does not open, no alarm times are updated

App version 1.26 immediately crashes. I have tried force-stopping + clearing the cache and I rebooted my phone. Didn't want to clear data quite yet.

Galaxy S22 Ultra, One UI 6.1 (Android 14).

Happy to provide additional info. Thanks for all your work on this app! It's the reason my lights fade on nicely in the morning before my alarm time.

Reproducible Builds

I've checked your app if its build is reproducible (see: Reproducible bulds, special client support and more in our repo), but while I was able to successfully generate the APK using ./gradlew assembleRelease, resulting APKs differ:

-------------------------------
--- /dev/fd/63  2024-07-22 13:49:55.081416991 +0200
+++ /dev/fd/62  2024-07-22 13:49:55.081416991 +0200
@@ -1,11 +1,11 @@
   META-INF/com/android/build/gradle/app-metadata.properties
   32-bit CRC value (hex):                         d1f06b7f
   assets/dexopt/baseline.prof
-  32-bit CRC value (hex):                         e1612f97
+  32-bit CRC value (hex):                         17c98cce
   assets/dexopt/baseline.profm
   32-bit CRC value (hex):                         ca05ad5b
   classes.dex
-  32-bit CRC value (hex):                         38d9f357
+  32-bit CRC value (hex):                         92ed9efe
   DebugProbesKt.bin
   32-bit CRC value (hex):                         7cded4df
   META-INF/androidx.activity_activity-ktx.version

Looking inside yours, and comparing with the commit behind the tag, the APK cannot have been built from that commit as the version bump only happens in the next commit. But when I build from that, the diff becomes huuuuge. So I assume the APK was built after the tag was created, with uncommitted local modifications applied. In which case RB is impossible.

We'd appreciate if you could help making your build reproducible. We've prepared some hints on reproducible builds for that.

Looking forward to your reply!

Alarm in the same hour is in UTC format and not in GMT+1

I'm having an issue with the time format. I think there is an error with formatting it to UTC. I have updated to the latest version of the app. The issue was already there with the previous version.

Time of testing: 01:20 local time or 00:20+1 (GMT+1)

Alarm in phone: --- Value in HA:
01:50 / 00:50+1 --- 01:50+1 <-- Incorrect
02:50 / 01:50+1 --- 01:50+1
03:50 / 02:50+1 --- 02:50+1
04:50 / 03:50+1 --- 03:50+1

If the alarm is within the same hour (max 60 minutes from now), the format is not in GMT+1 but GMT+0 or UTC. This shouldn't be the case. The screenshot is when the alarm is set to 01:50 local time so HA needs to output Wed Dec 23 00:50:00 GMT+01:00 2020

Schermafbeelding 2020-12-23 om 01 42 46

Possible to show next alarm in HA card?

Hey, so I just got the hassalarm installed and I'd like to see my next alarm in a card in HA card, is it possible? if yes, how?
"Next alarm: tommorow OR mon,tue,wed..... at 00:00"

Showing alarm when none is

Sometimes Hassalarm gets an alarm which is not set (see both screenshots). I am using the Google alarm clock app on Samsung S10e.

Screenshot_20200626-085108_Clock

Screenshot_20200626-085100_Hassalarm

Next alarm always showing as January 1, 1970, 12:00 AM

I just set it up the first time, and feel like I did everything correctly according to the readme, but I'm not getting the proper alarm time and date in home assistant.

grafik

My configuration.yaml

# Sensors
sensor:
  - platform: time_date # for Hassalarm
    display_options:
      - 'date_time'

# For Hassalarm
input_datetime:
  next_alarm:
    name: Nächster Wecker
    has_date: true
    has_time: true

My automations.yaml (for webhook).
Note, I haven't created any automation to use the alarm yet.

- id: 'hassalarm'
  alias: Webhook for Hassalarm
  trigger:
    platform: webhook
    webhook_id: hassalarm-webhook-2323
  action:
    service: input_datetime.set_datetime
    data_template:
      entity_id: "{{ trigger.json.entity_id }}"
      datetime: "{{ trigger.json.datetime }}"

The app reports "Published Successfully" and correctly shows what the next scheduled alarm is.

Any ideas? Thanks!

Alarm label

Hi,
Is it possible to also get the alarm label ?
Thanks for the great work !

Won't work I think I have an issue with 12h vs 24 hr clock time

My automations won't trigger even though my next alarm is being updated and my date & time is correct, what I think may be the issue is that my alarm times reports as 8:30 AM and my date & time sensor is reporting on a 24 hour clock without Am/Pm so they never truly match and the automation never fires. Is there a way I can fix this?

stopped working

Hello,

I have something very strange, the app worked fine but stopped working for some reason on 19 december.
Now, if I try to replicate what's in the log in python on my laptop it doesn't work either ...

from requests import get,post
import json
import headerfiles as parameters
headers=parameters.headers
address_hass=parameters.address_hass

url='http://'+address_hass+':8123/api/services/input_datetime/set_datetime'

payload='{"entity_id": "input_datetime.next_alarm","timestamp": "1609911060"}'

test=post(url,data=payload,headers=headers)
test.text

This leads to '400: Bad Request' (same messages as on my phone).

However, if I change the payload to payload='{"entity_id": "input_datetime.next_alarm","datetime": "2020-01-06 06:31:20"}', it works fine.

So I'm wondering if something went wrong with using this timestamp payload?

regards
Stijn

Feature Request: History of alarms

Hi. A history of alarms would be cool; even if only 1.

I ask this because I'm hunting down an errant app that seems to be creating then immediately deleting an alarm.

A bit of backstory; I switched to this app after facing the same issue using the official Home Assistant app (where I have an automation that works with the Next Alarm sensor)

Alarm has changed before automation can be triggered

Hi,
I´m still testing hassalarm on Samsung S10E and the next alarm value is triggered correct.
I´m using an automation based on your example, but if the alarm is triggered on my phone, the next_alarm is set to the next one, immediately.
These seems to happen so fast, that the automation is not triggered...
Can you add some delay or do you have any idea, how can I solve the problem?
Thank you!

Regards, Michael

FR: Store app (intent) which triggered a certain alarm update

I've been facing the issue as in #19. Ignored apps is a good fix. My challenge is to know which app to block. At the moment, the only way to do this is by acting on the moment it's been set up as "next alarm" to ignore it. However, I might not have a chance to check at that moment. I would love to understand for all the history of publishes, which app triggered which.

In short, the request here would be to store and show the app source of the alarm on the "Publish history".

For example, instead of:
@23-03-25 10:48:17 alarm @: 23-03-26 09:30

Show something like:
@23-03-25 10:48:17 alarm @: 23-03-26 09:30 by "com.sec.android.app.clockpackage"

Alternatively, this information could be shown on click, similar to the popup information when you click on errors.

At the moment, this would be only for information, so we can diagnose the source of the problematic apps to ignore. In the future, we could also change it so you could have a one click to add that app to the Ignore apps list.

Support for host without port

I am running hass behind a reverse proxy, thus I don't need/want a port.
Currently if no one is specified it automatically appends 8123 as the port.

Unable to connect with SSL self signed certificate

Screenshot_20201217-074627~2

The following issue is occuring when trying to connect to my HA Instance via SSL using self signed certificates. Both the Root and Intermediate CA are installed in Android and Chrome showes the connections certificates as valid. Is there any remediation for that issue?

Hassalarm does not determine the correct date / time for the upcoming alarm

Hassalarm does not determine the correct date / time for the upcoming alarm. In case of the settings below it says the next alarm is today (Saturday) at 15:33. I have no (in)-active alarm today or any alarm on that time

Alarms set:

  • Monday - Thursday 07:00
  • Friday 08:00

Hassalarm version 1.1
Samsung A70
Android 9

APK download

Are there any plans to make the app available outside of Google's walled garden – e.g. by providing the APK attached to its corresponding release tag here, or bringing it to F-Droid?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.