Pssssst, you can use input_text
and the service call input_text.set_value
to set ASCII values.
Or if you want to record the commute between all zones, how about this:
- alias: Leave any zone
trigger:
platform: state
entity_id: device_tracker.pauls_iphone
to: 'away'
action:
- service: input_number.set_value
data_template:
entity_id: input_number.commute_start_time
value: '{{ as_timestamp(now()) }}'
- service: input_text.set_value
data_template:
entity_id: input_text.commute_start_zone
value: '{{ trigger.from_state.state }}'
- alias: Enter any zone
trigger:
platform: state
entity_id: device_tracker.pauls_iphone
from: 'away'
action:
service: ifttt.trigger
data_template:
time: '{{ as_timestamp(now()) - (states("input_number.commute_start_time")|int) }}'
zone1: '{{ states("input_text.commute_start_zone") }}'
zone2: '{{ states("device_tracker.pauls_iphone") }}'
My only concern with the input_number was the fact that a signed integer limit is close to as_timestamp(now()). I wasn’t sure how home assistant handles overloading a bit. So it would be safer to store the value as a string.
as_timestamp() returns a float, not an integer, and input_number stores the value as a float, not an integer. Or, at least, that’s how it works as best as I can tell. If so, I can’t see that using an input_number would be a problem. But whatever “floats” your boat!
Eh, it’s the same issue potentially, all floats under the hood are integers that store higher values and move the decimal place.
Anways, I checked the int/float limit in python and apparently it’s dynamic so it won’t pose a problem. input_number away @ptdalen
I want to know the time, but also the start and end zone.
That is why I thought I’d write the current friendly name of the zone I’m in when changing FROM away to I think Input_text, then when I go TO Away, write the value of current location to another input text called previous location.
Bascially it would be a shell game. While I was in the away mode, both previous and current would be the same, but as soon as I arrive somewhere, I end up with two sensors. One would be where I’m at , and one would be where I was last. Then I subtract the time stamps from those sensors, and get a commute time.
Then it does not matter if I add more zones in the future, I can add as many as I want and track time from zone to zone.
Once I get that, I have a simple IFTTT to send those three variables to a google spreadsheet. I can keep a history of commutes, etc. I had this working with ST, but it really was not a ST thing, it was just passing variable from a presence sensor (previous, and current), and doing a little math.
Just a fun project, I know I can do this with MQTT, but it seemed like it should be easy to set a “variable” with text pulled from the state of another sensor and make them match, and it seemed like it would be easy to subtract the state change times, and end up with total.
Thanks everyone, I have a lot of good info, here when I get a working automation, I’ll share it.
Ignore my last post I must have been tired. You provided exactly what I was looking for, haha. I’m in the process of setting this up now and will report back with the results. Once it’s done and working, I’ll post something showing the whole process including the IFTTT webhook and sending data to google docs.
Thanks again
One dumb question, and it’s more of a YAML fomating question
is this
service: ifttt.trigger
data_template:
event: CommuteLog
value1: '{{ states("input_text.commute_start_zone") }}'
value2: '{{ states("device_tracker.pauls_iphone") }}'
value3: '{{ as_timestamp(now()) - (states("input_number.commute_start_time")|int) }}'
the same as
service: ifttt.trigger
data_template: {"event":"CommuteLog", "value1":"{{ states("input_text.commute_start_zone") }}", "value2":"{{ states("device_tracker.pauls_iphone") }}", "value3":"{{ as_timestamp(now()) - (states("input_number.commute_start_time")|int) }}"}
Also, I’ll add this to my configuration.yaml
input_text:
commute_start_time:
name: Commute Start Time
input_number:
commute_start_zone:
name: Commute Start Zone
Also if I wanted minutes vs seconds, I could just do this right?
value3: '{{ (as_timestamp(now()) - (states("input_number.commute_start_time")|int))/60 }}'
thanks again for the awesome logic, I think this will work well for me
Yes, that should work. Would be a bitch to debug if you go with the bottom version.
Yes that should work if you want value3 in minutes.
When it doubt, try this:
http://yaml-online-parser.appspot.com/
E.g.:
Regarding the additions to configuration.yaml, I would have thought you have input_text and input_number reversed.
Lastly, yes, I think that expression should work for reporting minutes instead of seconds. You might also want to add “(…)|round” to round to the nearest minute.
thanks, I did have them reversed.
Cant wait to drive around and check this out,ha
service: ifttt.trigger
data_template:
event: CommuteLog
value1: '{{ states("input_text.commute_start_zone") }}'
value2: '{{ states("device_tracker.pauls_iphone") }}'
value3: '{{ ((as_timestamp(now()) - (states("input_number.commute_start_time")|int))/60)|round }}'