Hi. I have lurked and read a bit before asking.
I have a dehumidifier, controlled by a wemo smart plug, hereby switch.jolly.
The idea was to make the switch start when the netatmo sensor is above a slider input AFTER SUNSET and when it is the input +5% ANY TIME.
The switch, without the check, fires with no problem.
I have tried so many way I am about to surrender, but… what is wrong with this automation?
why does it never switch the .jolly on?
You have no case for your if and else. Service_templates require a result for all paths of an if statement:
To clarify, you have:
if x:
else if y:
do y
else if z:
do z
What happens if you don’t have y or z in this case? Nothing if it’s X and nothing if anything other than X, Y, or Z.
So to rectify your problems, we need to add a service for your first if statement. Then make sure you have a blanket else statement to catch all cases. We can also remove your else if for the off statement because it’s 100% opposite from the other else if. This can simply be changed into your else statement.
- id: '1540048399804'
alias: Deumidificatore sempre
trigger:
- platform: time
minutes: '/30'
seconds: 00
action:
- service_template: >
{% set humidity = states('sensor.netatmo_interno2_humidity') | float %}
{% set threshold = states('input_number.slider1') | float %}
{% set below_horizon = is_state('sun.sun', 'below_horizon') %}
{% if humidity >= threshold and below_horizon %}
switch.turn_on
{% elif humidty - 5 >= threshold %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
Sorry, my fault. I explained the case very badly.
the last elif was a check of ANOTHER slider (slider2) that switches off the switch anytime.
I have searched for a “range slider” between the components, but the best I could do is to set a max and a min threshold.
Maybe can I put something like the following?
if I need an “escape” clause with no IF, can I cover all the cases just to be sure the last else never happens?
(The caveat is that in the (ahem! err…) “language” that I knew, if an “if-then” is not true, the program goes on as if nothing happened).
What’s the point? Those fringe cases only occur when the sensor will error out. Even if you try to make it not hit the else, you still need to have an entity in the else case. Otherwise you will have an error.
I don’t understand the point of having the minimum threshold. Anything lower than the threshold is going to turn the system off anyways. Why have a minimum threshold when that’s the case?
Because otherwise the system would shut down the dehum in a range of 1% (and in intervals of 30’), I think.
I need it to switch on, say, at night at 60% -or anytime at 65% and to run continuosly until it has reached i.e. 50%, then switching off regardless of the sun.
without a min threshold, it would switch off at 59% and 64% respectively, if I well understand how it works.
I think the problem at this point, if the last code I posted is feasible, was my misconception of the else clause and the necessity of a “pure” else, isn’t it?
Pardon me for my bad explaining of the use-case, english is not my first language.
Thank you again for the patience.
You don’t want to turn on or off the dehumidifier if its between 50 and 59?
The way that your if statements work is that no matter what, if you are below the max thresholds, it’s going to turn off the system. You’d need a condition that does nothing between 50 and 59.
This autmotion here will turn off below 50, do nothing between 50 and 59 and conditionally turn on when above 60.
- id: '1540048399804'
alias: Deumidificatore sempre
trigger:
- platform: time
minutes: '/30'
seconds: 00
action:
- condition: template
value_template: >
{% set humidity = states('sensor.netatmo_interno2_humidity') | float %}
{% set minimum = states('input_number.slider1') | float %}
{% set maximum = states('input_number.slider2') | float %}
{{ not minimum <= humidity < maximum }}
- service_template: >
{% set humidity = states('sensor.netatmo_interno2_humidity') | float %}
{% set threshold = states('input_number.slider1') | float %}
{% set below_horizon = is_state('sun.sun', 'below_horizon') %}
{% if humidity >= threshold and below_horizon %}
switch.turn_on
{% elif humidty >= threshold + 5 %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
Ok, given the fact that maybe slider1 is for the maximum and slider2 for the minimum (it is not so, I have understood NOTHING),
I think I have understood what you have done: you added a condition that stops the template when humidity is between the two values. isn’t it?
Now I see the error in my code: the last else switches off for intermediate values.
Sorry for the trouble.
And thank you again for the valuable lessons.