Get only numeric field from states.sensor.google_travel_time__driving.attributes.duration_in_traffic

Hi all!
I’m trying to make a script to calculate the time between my house and my work.
But I’m Brazilian, and need to change the default value ( like 10 mins ) to only numeric field ( 10 ).
I’m using the states.sensor.google_travel_time__driving.attributes.duration_in_traffic default value to get it.
How can it be done?

The duration in traffic is stored as a state for that sensor. You should be able to use:

states.sensor.google_travel_time__driving.state

and it should return the value.

Or you can use the following:
{{ states.sensor.google_travel_time__driving.attributes.duration_in_traffic | replace(" mins","") }}

It WORKED!!

Thanks a lot!!!

This is quite an old post but still seemed the most relevant. I’m trying to do some math with the google traffic sensor and cannot quite figure out what I’m missing

My goal is to take the duration in traffic which is the current commute time, subtract duration, which is the normal commute time, then divide the value by duration. This will give a percentage how much longer than normal traffic is. I’ll use that in automation, etc.

For example
This provides the value I want

{{ ((state_attr('sensor.pauls_time_to_work_google','duration_in_traffic') |replace(" mins","")| int)  -  (state_attr('sensor.pauls_time_to_work_google','duration') |replace(" mins","")| int))/(state_attr('sensor.pauls_time_to_work_google','duration') |replace(" mins","")| int) }}

Basically I’ll come up with sensor saying if the value is over .25 traffic is heavy, over .10 it’s moderate, and anything less is normal.

I’ve tried this, but it’s not quite right.

          {% if (((state_attr('sensor.pauls_time_to_work_google','duration_in_traffic') |replace(" mins","")| int)  -  (state_attr('sensor.pauls_time_to_work_google','duration') |replace(" mins","")| int))/(state_attr('sensor.pauls_time_to_work_google','duration') |replace(" mins","")| int)  >= .25 ) %}
            Heavy