You don’t want the readings to be carried out or you don’t want to see them on your dashboard?
I have no solution for the former, but you could achieve the latter with putting the sensor in a group and then make this group visible from 16h - 18h only.
I set up my own template sensor indicating working hours that could easily be adjusted - here’s a draft version:
- platform: template
sensors:
traveltime:
friendly_name: TravelTime
# traveltime is Mon-Fri, starts at 16:00h and lasts until 18:00h
value_template: '{{ now().weekday() in (0,1,2,3,4) and now().hour >=16 and now().hour <= 18 }}'
You might then be able to use the output of the traveltime sensor to adjust the scan-interval:
- platform: google_travel_time
name: Home To Work
api_key: !secret googlemaps_api
origin: zone.home
destination: zone.work
scan_interval:
value_template: >-
{%- if states.sensor.traveltime.state == 'true' -%} 300
{%- else -%} 3600
{% endif %}
Not really sure about the syntax and if you can use a value_template there at all, but I guess it’s worth a try.
Maybe your if-condition needs to look like this:
{% if is_state('sensor.traveltime.state', 'true') %}
It appears you could make a really simple python script that you could run by shell command automation that will update the travel time sensor (i’d use mqtt)
- Invalid config for [sensor]: [value_template] is an invalid option for [sensor]. Check: sensor->scan_interval->value_template. (See /home/hass/.homeassistant/configuration.yaml, line 127). Please check the docs at https://home-assistant.io/components/sensor/
Bummer - maybe data_template works instead of value_template.
It’s strange, though, that it is an ‘invalid option for [sensor]’ - I would have expected to be about the scan_interval.
Is your spacing set up properly in the value_template?
- Invalid config for [sensor]: [data_template] is an invalid option for [sensor]. Check: sensor->scan_interval->data_template. (See /home/hass/.homeassistant/configuration.yaml, line 127
). Please check the docs at https://home-assistant.io/components/sensor/
I don’t think that it is spacing problem.
Do you have working example of this kind of configuration for any kind of sensor?
- Invalid config for [sensor]: [value_template] is an invalid option for [sensor]. Check: sensor->scan_interval->value_template. (See /home/hass/.homeassistant/configuration.yaml, line 127). Please check the docs at https://home-assistant.io/components/sensor/
and it works fine - so I think it’s not a general sensor or even scan_interval issue for the value_template.
Maybe it’s specific to the google_travel_time platform
Could you pate the last version of your config again?
But I’m basically out of ideas now.
Sorry!
# This will show the runtime of the HA Process on the Pi
- platform: command_line
name: "HA runtime"
command: echo "$(($(date +%s) - $(date -d "$(head -n1 /home/homeassistant/.homeassistant/home-assistant.log | cut -d' ' -f-2)" +%s)))"
scan_interval:
value_template: 60
value_template: >-
{% set lasttime = value | int %}
{% set minutes = ((lasttime % 3600) / 60) | int %}
{% set hours = ((lasttime % 86400) / 3600) | int %}
{% set days = (lasttime / 86400) | int %}
{%- if lasttime < 60 -%}
Less than a minute
{%- else -%}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{%- endif -%}
{%- if hours > 0 -%}
{%- if days > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if days > 0 or hours > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
{%- endif -%}