One of my binary sensors I found from a user here used to work. At some point, it stopped working properly. Not sure if it is from one of the updates (now on 2021.1.5) or a snapshot I install due to a faulty sd card on my rpi3. I think the cause is the now().timestamp()
?
In HA, when I check
{% set t = now().timestamp() %}
t = 1612241382.0
I convert 1612241382
using using an unix converter online and it shows that it is 9hrs behind my actual time zone. Are both suppose to be the same?
GMT: Tuesday, February 2, 2021 4:49:42 AM
Your time zone: Tuesday, February 2, 2021 1:49:42 PM GMT+09:00
My config file for time zone is set correctly.
homeassistant:
name: Home
latitude: !secret home_latitude
longitude: !secret home_longitude
elevation: 200
unit_system: metric
time_zone: Asia/Tokyo
This is the binary sensor in question. When I set the on and off input_datetime time within the range on the am hours, it never becomes true. Though it set to true about 9 hours later.
binary_sensor:
am_time_active:
friendly_name: "AM Time Active"
value_template: >-
{% set d = now().strftime("%Y-%m-%d ") %}
{% set t = now().timestamp() %}
{% set am_start = strptime(d + states('input_datetime.am_on_time'), '%Y-%m-%d %H:%M:%S').timestamp() %}
{% set am_end = strptime(d + states('input_datetime.am_off_time'), '%Y-%m-%d %H:%M:%S').timestamp() %}
{{ am_start <= t <= am_end }}