I've read a bunch of the posts on the forum for the same question, but I still can't get it to work.
Here's my code in the function node:
var last = global.get("homeAssistant.states['device_tracker.iphone_13'].last_changed"); var now = new Date().getTime(); var diff = now - last; msg.payload = diff; return msg;
The formatting for the last changed is
The error I'm getting is:
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.(2363)
So it's not thinking
last is the right format?
So I tried this:
var last = new Date('2022 - 12 - 11T02: 04: 19.408425 + 00: 00'); var now = new Date().getTime(); var diff = now - last; msg.payload = diff; return msg;
and I get the same message.
In tutorials I see random
; at the ends of lines, so I've tried different combinations of that too.
If I just put in a number instead of
last in the formula, it works.
This must be something super simple but I can't figure it out. There are probably a million different silly errors I could have. Anyone able to help me please?