Working hours

Morning,
question, i would create a calender in where i can see my working hours based on a device_tracker.
does anybody thinks that this is possible?
it would be nice to show that in an new calender.
looking forward to get some tips

If you create a zone called ā€œWorkā€, then something like this should work:

trigger:
  - platform: state
    entity_id:
      - device_tracker.me
    from: Work
condition: []
action:
  - service: calendar.create_event
    target:
      entity_id: calendar.work
    data:
      summary: At work
      description: At work
      start_date_time: "{{ trigger.from_state.last_changed }}"
      end_date_time: "{{ trigger.to_state.last_changed }}"
      location: Work

Maybe Iā€™d rather use a person entity, but you stated device tracker. a person entity should work too.

3 Likes

Do you specifically want a Calendar or are you just interested in tracking hours?

Hi Edwin,
thanks for the sample.
i want to see in the calendar, on what time leaving home and at what time iā€™am back.
that only for monday untill friday.
that by using a device tracker.

The monday till friday bit can be put in the conditions. But as this registers when you arrive at work and when you leave, I do not see why it is needed. If you do not go to work it will not do anything (and if you do, wouldnā€™t you want to know?

The leaving home bit is much harder. You never know in Home Assistant why you leave home. And what if you are at a friends place, and are then called to go to work from there? Or need to go to the dentist during working hours? Or if you go to a shop to buy some food straight from work?

You could save the time you enter and leave home, and when you are at work. If the time at work is between leaving and returning, then create the event. The principles are the same as in the example. But I think you will have many cases where it wonā€™t work as expected. So what I gave you is just work, but truthful in all these cases.

1 Like

Clear answer.
The problem is that i do not have a fixed work zone.
Because of the fact that i drive around the country.

Then you asked the wrong question. Because then you want to know all the times you were not home on weekdays. This will inevitably lead to problems when you leave home on weekdays and return in the weekend, or vice versa.

Create a binary sensor to see of you are home or not. (this is needed to filter out other zones you might visit while you are gone.) Then replace the devicetracker instance in my example with the binary sensor. And add a condition for the weekdays.

thanks again.
first i will try to add the binary sensor but donā€™t know how to do that.
sorryā€¦newbie

You can create a template (binary) sensor in the home assistant settings, under helpers.

Place this in the field for the state template, be sure to replace the device_tracker entity by the one you need.

This tells you if you are home:

{{ is_state('device_tracker.me','home') }}

Honestly, I canā€™t see something here, that would work without issues. If you use your home (arriving/leaving) that would not work on holidays for example. If youā€™d pin it to your work, that canā€™t work if you donā€™t have an office (in the conventional sense :laughing:). If you pin it to the car, you canā€™t drive to the supermarket without being ā€œat workā€.

In this case, Iā€™d advise to look for something, that you really only use, if youā€™re working. Eg. a work phone, a login to a company computer or network, something like that. It would make much more sense, to work with something like that.

And if you donā€™t have anything like that, Iā€™d rather think about a BT beacon, that you hang on your working tools. A BT beacon connected to your sawā€¦anything would be better, than relying on ā€œhomeā€ or ā€œnot_homeā€. :slight_smile:

But itā€™s your question, let us know more about how you work and what you do, so we can think about better solutions. :slight_smile:

This will help me out to test some several things.
Thanks again

Some explanation from my side.
iā€™am working as a service engineer with customers around the country, in this case The Netherlands.
an as you suggested, i am using a ā€œWork Phoneā€ only at the time whem i am working.
so maybe i can figure out something with this phone.

If there isnā€™t a definitive source of truth, your next best bet is probably to use the Bayesian binary sensor to combine values from multiple sensors to determine when you are most probably ā€œat workā€.

OK, that sounds good, as you can use that as relatively unique possibilty to get your work status.

When exactly do you use that work phone? Is it on before you ā€œgo to workā€ or do you turn it on when you get to the car? Depending on how you exactly use it, it should be possible to be relatively exact in determing the times you work.

If so, you could go with something like phone == on while not in ā€œhome_zoneā€.

Please describe exactly, how you use that phone (regarding the work time :laughing: ), maybe some other ideas come up. Or just fiddle around and let us know what you came up with! :slight_smile:

OK.
Created an Work calender.
Create an binary_sensor
The phone is always ON and in the WIFI network.
When leaving home the phone is not in the WIFI network anymore.
So, when leaving home the time needs to start in the (work) calender.
Then, when arriving home and the phone is in the WIFI network again it should shown that in the calender. That means that there should be an time leaving untill arriving displayed in the calender.
i 'll tryed this (see below)

alias: werk
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.home_or_not_home
    from: Work
condition: []
action:
  - service: calendar.create_event
    target:
      entity_id: calendar.work
    data:
      summary: At work
      description: At work
      start_date_time: "{{ trigger.from_state.last_changed }}"
      end_date_time: "{{ trigger.to_state.last_changed }}"
      location: Work

but when testing this automation i get an error

Executed: June 10, 2024 at 7:27:55 PM

Error: Error rendering data template: UndefinedError: ā€˜dict objectā€™ has no attribute ā€˜from_stateā€™

i thought it would be a bit simpeler butā€¦?
Any tips are very welcome

EDIT.
Also tryed this oneā€¦

alias: Start working time
description: ""
trigger:
  - platform: zone
    entity_id: device_tracker.os_hev_19_21_location
    zone: zone.home
    event: leave
condition: []
action:
  - service: calendar.create_event
    metadata: {}
    data:
      summary: start
      description: Start working time
      start_date_time: "2024-06-10 00:00:00"
      end_date_time: "2024-06-11 00:00:00"
      start_date: "2024-06-10"
      end_date: "2024-06-11"
    target:
      entity_id: calendar.work
mode: single

Based on the car i'am driving
But then the error is something like this....

**Executed: June 10, 2024 at 7:57:21 PM**
**Error: must contain at most one of start_date, start_date_time, in.**

You cannot test automations that rely on the trigger variable by using the ā€œRunā€ button in the Automation editor.

However, more importantly, the trigger in the first automation will never fire. Binary sensor only have ā€œonā€/ā€œoffā€/ā€œunavailableā€ as valid statesā€¦ the ā€œfromā€ state will never be ā€œWorkā€.

The error in the second automation is due to the fact that you have provided too many configuration variables. The variables start_date and end_date are only for all-day events and cannot be used at the same time as start_date_time and end_date_time.

In addition to the answer above, the trigger should fire when you come home, because that is when the end of the away period is known.

The reason for the binary sensor is that there can be many states the device tracker has when you are not home (if you define zones). The binary sensor was suggested to make sure that does not affect the automation.

Hi there,
Still busy with this.
Indeed with the workphone it works looking at when the workphone is available in the wifi network, but because itā€™'s an iPhone the wifi is going to sleep sometimes.
Now i bought an bt key finder (iTag) but am not able to integrate this.
Running HA on an Nuc with bt adapter, but it isnā€™t regonized the iTag.
Do you have any tips regarding this?
Thx in advance

Oh yeah, I had my fair share of non-working BT tags/beacons. :laughing:

Sorry, but with BT devices, there are so many possibilties, I need some more informationā€¦ :wink:

  • What tag did you buy exactly (please provide a link, if possible)?
  • What BT adapter do you have?
  • What did you try to implement it?
  • Do you want to use it only for your ā€œworking hour challengeā€ or do you want to use it on something different as well (like tracking inside the house)?
  • Where (physically) is the BT dongle/HA located in relation to the BT tag? Eg. is your BT dongle in your livingroom on the west wing in your castle, and the frontdoor is in the east wing?

:slight_smile:

Hi
Using this one

In the Nuc itselfs there is an bluetooth adapter.

Try to see if the iTag is being seen by the Nuc bluetooth adapter.

Not living in a castle, otherwise i wouldnā€™t need something to see my ā€œwork timesā€ anymore:)
Distance between both max 8 meters