Here is link if someone have similar ir light.
I try to make new automation + python I already have working version with one problem.
Here is link.
On remote I have only one button of on and off. When I decrease fan speed and when I add slider to 1 automation call FAN + DOWN in python script because I configured it like that:
part from automation:
{% elif slider == 1 %}
6
part from python:
elif cmd == 6:
service_data = {âhostâ:â192.168.2.1â, âpacketâ:â{}â.format(rf[âFANâ])}
hass.services.call(âbroadlinkâ, âsendâ, service_data, False)
time.sleep(0.55)
loop = 1
rfc = rf[âDOWNâ]
Question: What I must add to line {% elif slider == 1 %}
to only trigger that line when I increse slider?
When diff is positive number. --> {% set diff = (from - to) | round(0) %}
I figured out. Simple
{% elif slider == 1 and diff == '-' %}
If diff
is the result of a subtraction then diff == '-'
will always return false
.
I donât know theoretically but I did like I say and is working
Iâm glad to hear it is working for you. Although, honestly, I donât know what you expect it to do because the following statement will always evaluate to false
.
{% elif slider == 1 and diff == '-' %}
For the elif
statement to evaluate to true
, both slider==1
and diff='-'
must be true
. The problem is diff=='-'
is always false
. So this elif
can never be true
and whatever code is underneath it will never execute.
You should listen to @123. Heâs right. This will never ever be anything other than false.
This should only trigger on positive differences.
{% elif slider == 1 and diff > 0 %}
I donât know why but solution you suggested not working.
My solution works
{% elif slider == 1 and diff == '-' %}
Well you havenât posted your full template so we are assuming youâre doing the math correctly. If you post the full template, we can help steer you towards a correct template and a robust automation.
Link is dead, is that a private repo? Can you just copy/paste the template?
####################################################
# FAN CONTROL
####################################################
- alias: 'ir_kitchen_hood_fan_set'
trigger:
platform: state
entity_id: input_number.ir_kitchen_hood_fan_speed
action:
service: python_script.ir_kitchen_hood_fan_control
data_template:
command: >-
{% set to = trigger.to_state.state | int %}
{% set from = trigger.from_state.state | int %}
{% set diff = (from - to) | round(0) %}
{% set slider = states('input_number.ir_kitchen_hood_fan_speed') | round(0) %}
{% set step = (diff / 1) | round(0) %}
{% if slider == 0 %}
0
{% elif slider == 1 and diff == '-' %}
6
{% else %}
{{step}}
{% endif %}
Link is now working.
What are the values for from
and to
that make diff
equal to -
{% set diff = (from - to) | round(0) %}
Answer: There are no values that can make diff
equal to -
This is true:
4 - 6 = -2
this is not possible:
4 - 6 = -
You keep saying âit worksâ so youâre suggesting that this statement will evaluate to true
{% elif slider == 1 and diff == '-' %}
6
The problem is it can never evaluate to true
because diff == '-'
is always false
. It doesnât matter if slider==1
is true
, the other half is always false
. Therefore, the elif
will never report 6
.
Whatever way you think this thing âworksâ is not working the way you think it does.
Anyway, Iâve done my best to try to convince you that this can never be true:
4 -6 = -
I wish you luck with all of your future automations.
I appreciate all your help.
I donât know why my automation is working, make no sense.
But it works.
for giggles, remove the elif statement and see if it still works. Iâm guessing it will.