Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google home timers, custom time format #19

Closed
Frooodle opened this issue Sep 5, 2021 · 18 comments
Closed

Google home timers, custom time format #19

Frooodle opened this issue Sep 5, 2021 · 18 comments

Comments

@Frooodle
Copy link

Frooodle commented Sep 5, 2021

I am trying to setup google home timers with this however their time format is a bit different, i cant show debug info due to some issues but this is attribute data. Any ideas?

entity name is sensor.kitchen_display_timers
state is 2021-09-05T22:27:04+00:00
state attributes are...

next_timer_status: set
timers:

  • timer_id: timer/xx-xx-xx-xxx-xx
    fire_time: 1630880824
    local_time: '2021-09-05 22:27:04'
    local_time_iso: '2021-09-05T22:27:04+00:00'
    duration: '0:20:00'
    status: set
    label: null

integration: google_home
friendly_name: Kitchen display timers
icon: mdi:timer-sand
device_class: timestamp

Only mention of a start time i can see here is from update time values or from doing end minus duration since in example above
fire time (epoch) and local times all have the end time of the timer
image

@rianadon
Copy link
Owner

rianadon commented Sep 6, 2021

This looks like a duplicate of #18, so I'm going to close this one and move discussion there!

@rianadon rianadon closed this as completed Sep 6, 2021
@Frooodle
Copy link
Author

Frooodle commented Sep 6, 2021

@rianadon I first posted in that ticket but the difference was timer vs alarm so i moved to a new ticket and deleted comment instead since some attributes were different, but i guess its same enough..

@rianadon
Copy link
Owner

rianadon commented Sep 6, 2021

Oh sorry my bad I didn't see the distinction. I'll reopen!

@rianadon rianadon reopened this Sep 6, 2021
@rianadon
Copy link
Owner

rianadon commented Sep 6, 2021

For the timer, I see you have both a duration and local_time_iso atrributes. Do using those as the duration and end_time properties respectively work?

You will also need to set guess_mode: true, since the timer state is not a constant.

@gmcaesar
Copy link

gmcaesar commented Sep 7, 2021

I just tried this cause I'd like this too, but I get an error showing "cannot use "in" operator to search for "fixed" in local_time_iso"

Config:

type: custom:timer-bar-card
entity: sensor.kitchen_speaker_timers
end_time: local_time_iso
duration: duration
guess_mode: 'yes'

@Frooodle
Copy link
Author

Frooodle commented Sep 7, 2021

finally got debug info now with config
type: custom:timer-bar-card
entity: sensor.kitchen_display_timers
end_time:
attribute: local_time_iso
duration:
attribute: duration
guess_mode: true
debug: true

debug info is
State: 2021-09-07T20:24:13+00:00 (state mode = idle)
Mode: idle (auto mode = N/A, used)
Duration: second
Time remaining:
Counter:
Attr: {"next_timer_status":"set","timers":[{"timer_id":"timer/xxxx-xxx-xx-xxx","fire_time":1631046253,"local_time":"2021-09-07 20:24:13","local_time_iso":"2021-09-07T20:24:13+00:00","duration":"0:10:00","status":"set","label":null}],"integration":"google_home","friendly_name":"Kitchen display timers","icon":"mdi:timer-sand","device_class":"timestamp"}

The result card is just
image

@rianadon
Copy link
Owner

Sorry about the long response time!

@gmcaesar The format for duration is not so simple, due to me trying to support a few different options. The end_time and duration options take a dictionary, like this: end_time: { attribute: "local_time_iso" }.

Making a simpler visual editor for the configuration is on the todo list, but I won't have time for it for a while.

Thank you @Frooodle for the debugging information. I see the problem: there's actually no local_time_iso attribute! The local_time_iso is inside this timers list.

I'm very unfamiliar with these google home timers. Will there ever be more than one? Is this entity supposed to represent a group of timers? Nevertheless the card does not support attributes nested inside attributes at the moment.

@gmcaesar
Copy link

Yes I found that {attribute: } and changed it, and yes there can be more than one timer running at a time

@rianadon
Copy link
Owner

If there is potentially more than one timer, I don't think there is any clean way to do this without templates.

The you would have to create a template entity for the first timer, second timer, etc

A nicer method would be creating a new card for a google home timer set entity that embeds the timer bar card, similar to how my opensprinkler card is a special case of timer bar card for sets of sprinkler valves. This isn't something I'd be able to maintain due to my lack of access to Google Home, but if anyone wants to do this I'd gladly help with the initial code.

@Frooodle
Copy link
Author

I see the state value of the timer sensor is that of the last timers local_time_iso, perhaps for a single timer usecase we can pickup that state value for end_time rather than looking inside timers itself if that cant be done?
I dont know about anyone else but i would never use more than one timer anyway

@rianadon
Copy link
Owner

Good idea! I'll add an option for using state values.

@rianadon
Copy link
Owner

Published in 1.11!

Unfortunately, duration is still embedded within that timer list, so you'll need to either pull it out with a template, or use duration: { fixed: "0:10:00" }.

@gmcaesar
Copy link

gmcaesar commented Sep 19, 2021

I have tried a couple of ways to get this working and for some reason no go..... I must be missing something

attempt number one:

type: custom:timer-bar-card
entity: sensor.kitchen_speaker_timers
guess_mode: true
duration:
entity: input_number.kitchen_timer_duration
units: minutes
end_time:
entity: input_datetime.kitchen_timer

debug on this returns:

State: 2021-09-18T22:08:55-07:00 (state mode = idle)
Mode: idle (auto mode = N/A, used)
Duration: 1800 second
Time remaining: 2843.551
Counter: 2843.554
Attr: {"next_timer_status":"set","timers":[{"timer_id":"timer/ea146ef7-ad6a-b13f-95c7-d9184f200802","fire_time":1632028135,"local_time":"2021-09-18 22:08:55","local_time_iso":"2021-09-18T22:08:55-07:00","duration":"1:30:00","status":"set","label":null}],"integration":"google_home","friendly_name":"Kitchen speaker timers","icon":"mdi:timer-sand","device_class":"timestamp"}

where both the end time and duration entities are set by a node red flow that pulls apart the sensor, then I thought maybe the end_time did not support the entity, so I tried this (with both guess mode true and false...):

type: custom:timer-bar-card
entity: input_datetime.kitchen_timer
duration:
entity: input_number.kitchen_timer_duration
units: minutes

debug on this returns:

State: 22:08:00 (state mode = idle)
Mode: idle (auto mode = N/A, unused)
Duration: 1800 second
Time remaining: -552.9960000000001
Counter: -552.9920000000002
Attr: {"editable":true,"has_date":false,"has_time":true,"hour":22,"minute":8,"second":0,"timestamp":79680,"friendly_name":"Kitchen Timer"}

if i had to guess it would be that the state is idle but am i missing something?

@gmcaesar
Copy link

found my own anwser - one more entity needed:

type: custom:timer-bar-card
entity: input_boolean.kitchen_timer
icon: mdi:timer
duration:
entity: input_number.kitchen_timer_duration
units: minutes
end_time: {{states('input_datetime.kitchen_timer') }}

@jazzyisj
Copy link

jazzyisj commented Sep 21, 2021

@gmcaesar

Here's a template sensor that works with the Google Home integration and this card. You'll have to create a template for each Google Home entity you need. This will only work for the first timer. You can create additional sensors for multiple timers per google entity by changing timers[0] to timers[1],timers[2]etc.

template:
  - sensor:
      - name: "Dining Room Display Timer"
        unique_id: dining_room_display_timer
        icon: mdi:timer
        state: >
          {% set entity = 'sensor.dining_room_display_timers' %}
          {% if state_attr(entity,'timers')|lower not in ['','[]','unknown','unavailable','none'] %}
            {% set status = state_attr(entity,'timers')[0].status %}
            {% if status == 'set' %} active
            {% elif status == 'paused' %} paused
            {% elif status == 'waiting' %} waiting
            {% else %} idle
            {% endif %}
          {% endif %}
        attributes:
          duration: >
            {% set entity = 'sensor.dining_room_display_timers' %}
            {% if state_attr(entity,'timers')|lower not in ['','[]','unknown','unavailable','none'] %}
              {{ state_attr(entity,'timers')[0].duration }}
            {% endif %}
          end_time: >
            {% set entity = 'sensor.dining_room_display_timers' %}
            {% if state_attr(entity,'timers')|lower not in ['','[]','unknown','unavailable','none'] %}
              {{ state_attr(entity,'timers')[0].local_time_iso }}
            {% endif %}
          integration: google_home  

The integration attribute is added so you can easily use an auto-entities card to display all of your google home timers in a card.

type: custom:auto-entities
filter:
  include:
    - domain: sensor
      entity_id: "sensor.*_timer"
      attributes:
        integration: google_home
  exclude:
    - state: unavailable
    - state: ''
    - state: 'idle'
sort:
  method: name
  ignore_case: true
show_empty: false
card:
  type: custom:timer-bar-card

image

@Frooodle
Copy link
Author

@jazzyisj Awesome! that works perfectly! doesn't work for timers greater that 24 hours but for my usecase thats fine, thanks!

@jazzyisj
Copy link

@Frooodle @gmcaesar
I had to make a little edit to that template. I didn't realize that the timers attribute is actually an empty list instead of null when there is no timer running. These changes will kill the warnings in the log. Small change in the auto_entities card to accomodate this also.

@SLaks
Copy link
Contributor

SLaks commented Apr 19, 2024

See #140 (comment) for better support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants