what do you mean by glitching?
As soon as HA is started The heat or cool required template sensors are in the wrong state. Probably because the zwave sensor they rely on has not initialised yet.
I attempted to mitigate this with a âglitch_delayâ sensor set as the first action in a start up automation. Unfortunately it was not fast enough to prevent the incorrect sate triggering the AC unit.
If I could access a HA start timestamp. I could prevent the AC automation running until 5 seconds or so after start up. Is there one?
Something like:
condition: state
entity_id: homeasistant?
state: on
for:
seconds: 5
Edit: maybe this,
sensor:
- platform: uptime
Edit 2: or maybe add a time to the heat required condition:
conditions:
- condition: state
entity_id: binary_sensor.lounge_ac_heat_required
state: 'on'
for:
seconds: 5
add this line to your templates:
{% if states.sensor.aeotec_lounge_temperature is defined %}
{{ states('sensor.aeotec_lounge_temperature') | float < states('input_number.lounge_ac_heat_temp_set') | float }}
{% else %}
False
{% endif %}
canât you set the retain flag on these events? I had that same issue in my first Z-wave integration in HA, but that solved nicely after having set the publisher to use retain on these events. No matter what, they always have a value.
Theyâre not mqtt sensors, can you do that with zwave?
Unfortunately this did not work @petro:
- platform: template
sensors:
rumpus_ac_heat_required:
friendly_name: "Rumpus AC Heat Required"
value_template: >-
{% if states.sensor.rumpus_room_temperature is defined %}
{{ states('sensor.rumpus_room_temperature') | float < states('input_number.runpus_ac_heat_temp_set') | float }}
{% else %}
False
{% endif %}
rumpus_ac_cool_required:
friendly_name: "Rumpus AC Cool Required"
value_template: >-
{% if states.sensor.rumpus_room_temperature is defined %}
{{ states('sensor.rumpus_room_temperature') | float > states('input_number.rumpus_ac_cool_temp_set') | float}}
{% else %}
False
{% endif %}
The AC unit still triggered on restart, when it should not have (I did check the final sensor states). Iâm going to try the for: seconds: 5
in the conditions.
22:30 [Lounge AC Heat Required] turned off
22:30 [Lounge Entrance Multisensor]changed to initializing
22:30 [Aeotec ZW090 Z-Stick Gen5 AU]changed to initializing
22:30 [Upstairs AC Mode] changed to Normal Heat
22:30 [Lounge AC Heat Required] turned on
22:30 [Lounge PM Automation Time Active] turned on
22:30 Home Assistant started
for a delay at startup You can use this;
- alias: 'Startup HA'
id: 'Startup HA'
initial_state: 'on'
trigger:
platform: homeassistant
event: start
condition:
condition: template
value_template: >
{{whatever you want}}
action:
- delay: 00:00:20
- service: whatever
not sure if you can delay the creation of a sensor thoughâŚunless youâd create it via an automation or script (have these in python eg)
Tried it. It did not work. See âglitch_delayâ in my image above (one event too late). This was the first service call in my start-up automation too.
I can because my zwave hub connects to HA via Mqtt
Checking to see that the sensor has been on for at least 10 seconds seems to have solved the problem:
- condition: or # And only if room heating or cooling is required (for the case of a time trigger)
conditions:
- condition: state
entity_id: binary_sensor.lounge_ac_heat_required
state: 'on'
for:
seconds: 10
- condition: state
entity_id: binary_sensor.lounge_ac_cool_required
for:
seconds: 10
history_stats is is⌠or?
2018-09-21 15:56:16 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/components/sensor/history_stats.py", line 114, in force_refresh
self.schedule_update_ha_state(True)
File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 289, in schedule_update_ha_state
self.hass.add_job(self.async_update_ha_state(force_refresh))
AttributeError: 'NoneType' object has no attribute 'add_job'
2018-09-21 15:56:24 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 325, in wrapper
result = method(*args, **kwargs)
TypeError: update() takes 1 positional argument but 2 were given
2018-09-21 15:56:24 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 325, in wrapper
result = method(*args, **kwargs)
TypeError: update() takes 1 positional argument but 2 were given
2018-09-21 15:56:24 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 325, in wrapper
result = method(*args, **kwargs)
TypeError: update() takes 1 positional argument but 2 were given
2018-09-21 15:56:24 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 325, in wrapper
result = method(*args, **kwargs)
TypeError: update() takes 1 positional argument but 2 were given
Still havent got a clue what to do here⌠deleted the history_stats sensors and the original error of the post above remains in the logâŚ
Then itâs unrelated to your history stats sensor. Not sure whatâs causing it because itâs coming from the core.
it donât repeat!
do you know why?
- id: timeroven
alias: oven_timer
trigger:
- above: '1'
entity_id: sensor.ovenoo
platform: numeric_state
condition:
- condition: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.automation.oven_timer.attributes.last_triggered) | int > 4 }}'
action:
- data:
message: oven is on!
service: notify.ios_vahids_iphone
- service: homeassistant.turn_on
entity_id: script.timed_lamp_oven
language Mr! you seriously removed my post yesterday over the - e x a c t - same thing.
I wasnât a moderator 2 years ago
as i read for days and days while resisting posting a question you undoubtingly already answered, i do see you are a incredible asset to the homeassistant community and i apologize for the heckling. this has been nothing but frustrating, this rubics cube / addiction that homeassistant is.
I have a daily light schedule that is set via an input_datetime entity within the UI. it happens daily, everyday.
I have a script that changes many things, and in that script it has the lights turning on. however the daily light schedule has the lights off for about thirty minutes. all im trying to accomplish is, timediff to time now to time of next occurance of schedule. i can format the string, to give me the 'hours / minutes / seconds result. but im struggling to get the string.
im coming to the conclusion that i need to add todays date/year format to the input_datetime, then time difference to now and ensure both are using timestamps instead of strings, then divide the seconds or epoch it returns?
sorry, i would post code and my attempts but itll be a book. however, i will post when i get home from work. day 3 on this. please. forgive me almighty templater.
This is super-great, thank you. Iâm using it in my smart heating control automation. Iâve found an interesting bug, that the value of t
is not coherent on all the systems, and it depends on the timezone set. To circumvent this, my fix is:
- condition: template
value_template: >
{% set t = strptime((now().timestamp() | timestamp_local), "%Y-%m-%d %H:%M:%S").timestamp()-strptime(now().strftime("%Y-%m-%d 00:00:00"),"%Y-%m-%d %H:%M:%S").timestamp() %}
{% set time_start = state_attr('input_datetime.heating_weekday_morning_start','timestamp') %}
{% set time_end = state_attr('input_datetime.heating_weekday_day_start','timestamp') %}
{{ time_start <= t < time_end }}
Thanks again.
it depends on how your datetime is configured. If your datetime doesnât use a date, thatâs not included with the timestamp. What you could have done is used strptime on your input_datetime states. Then t wouldnât change. Plus itâs easier to read.
{% set t = now().timestamp() %}
{% set fmat = "%Y-%m-%d %H:%M:%S" %}
{% set start = strptime(states('input_datetime.heating_weekday_morning_start'), fmat).timestamp() %}
{% set end= strptime(states('input_datetime.heating_weekday_day_start'), fmat).timestamp() %}
{{ start <= t <= end }}
I get UndefinedError: 'str object' has no attribute 'timestamp'
in template editor with this.
That means the format is wrong, if your datetimes do not have dates, you need to remove the dates from the fromat.
{% set t = now().timestamp() %}
{% set fmat = "%H:%M:%S" %} #<---- Change this to match input_datetime's state
{% set start = strptime(states('input_datetime.heating_weekday_morning_start'), fmat).timestamp() %}
{% set end= strptime(states('input_datetime.heating_weekday_day_start'), fmat).timestamp() %}
{{ start <= t <= end }}
Naaah. Itâs not the same.
It always returns false becaue the results:
{{ t }}
{{ fmat }}
{{ start }}
{{ end }}
are the following:
1604591220.001948
%H:%M:%S
-2208969600.0
-2208958200.0
My inputs are:
heating_weekday_morning_start:
name: Workdays morning
has_time: true
has_date: false
heating_weekday_day_start:
name: Workdays daytime
has_time: true
has_date: false
You donât remember your own code, do you ?
The thing is, you have to substract from the current time the midnight timestamp. The original problem was that now().timestamp()
returns the UTC time while I need the local times. Everything else is perfect.