Period of time of the work day sensor

Hi,
i’m trying to use a platform template that I found here.

- platform: template
        sensors:
          traveltime:
            friendly_name: TravelTimeToWork
            value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=6 and now().hour <= 8 }}'

And it works, but if I try to duplicate it, like the code below the raspberry crashes.

  - platform: template
    sensors:
      traveltime:
        friendly_name: TravelTimeToWork
        value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=6 and now().hour <= 8 }}'
  - platform: template
    sensors:
      traveltime:
        friendly_name: TravelTimeToHome
        value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=16 and now().hour <= 18 }}'

What I’m doing wrong?

Now I’ve changed this way but it gives me an error:

ERROR (Thread-5) [homeassistant.util.yaml] YAML file /home/homeassistant/.homeassistant/configuration.yaml contains duplicate key “traveltime”. Check lines 64 and 68.

- platform: template
        sensors:
          traveltime:
            friendly_name: TravelTimeToWork
            value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=6 and now().hour <= 8 }}'
          traveltime:
            friendly_name: TravelTimeToHome
            value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=16 and now().hour <= 18 }}'

You’re trying to set up two sensors with the same name.

You have to change one of the ‘traveltime:’ lines to something else.

1 Like

You have duplicate sensor names. Try this:

- platform: template
        sensors:
          traveltime_to_work:
            friendly_name: Travel Time To Work
            value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=6 and now().hour <= 8 }}'
          traveltime_to_home:
            friendly_name: Travel Time To Home
            value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=16 and now().hour <= 18 }}'

That was so simple uff, Thank you!