Can someone help me with the aumatics script, please?

I don’t understand the association perfectly yet, I only learn as a complete layman.
My request:

when the humidity in the “sensor.terarium_humidity” terrarium is less than 60%;
and
not more than 65%;
and
there is enough water in the tank “switch.level - off”
and
in the terrarium, the temperature of “sensor.terarium_temperature” is greater than 26
and
is the time of day between 8:00 and 18:00
turn on the “switch.th_meter” switch 1 per hour for 15 seconds

I can’t handle that cycle of 15 seconds 1 per hour


  alias: Déšť automatizace
  description: ''
  trigger:
  - below: '60'
    entity_id: sensor.terarium_humidity
    platform: numeric_state
  condition:
  - below: '65'
    condition: numeric_state
    entity_id: sensor.terarium_humidity
  - condition: and
    conditions:
    - condition: state
      entity_id: switch.hladina
      state: 'off'
  - condition: and
    conditions:
    - above: '26'
      condition: numeric_state
      entity_id: sensor.terarium_temperature
  - condition: and
    conditions:
    - after: '8:00:00'
      before: '18:00:00'
      condition: time
  action:
  - condition: state
    entity_id: switch.th_meter
    state: 'On'

Thank you for your help

Hey maceace,

first things first:
Your automation triggers whenever the humidity drops below 60%.
The first thing you check is if the humidity is below 65%, so that’s a bit redundant.
The automation won’t fire between 61-65%, so there’s not much point in that :slight_smile:

Also, your ‘and’ condition is redundant, you can either leave the “and” part since all conditions are “and” per default (automation only executes actions when ALL conditions are met).

As far as turning on the switch (the action): So you want this to turn on for 15sec, turn off and then, even if the humidity is lower than 60%. only turn on a hour later?

If that’s the case there’s two ways I can see this working:

  1. Either use a time pattern trigger, so the automation executes every full hour. Then it checks against all of the conditions, if they are met it turns on the switch for 15s.
    Downside: If the terrarium reaches 50% humidity at 14:01 it will be 59min before HA checks for that again.

  2. You could use a timer. A little more complicated, but basically:

  • Automation trigger: Humidity drops below 60% or timer finished.
  • Conditions: all conditions (including humidity, including “timer not running”),
  • Action: start a timer (counting down for 1h), turn on switch, delay 15s, turn off switch

first looks

first problem

when you do a

platform: numeric_state

check must be a number
so its

  - below: 60
    entity_id: sensor.terarium_humidity
    platform: numeric_state

not

  - below: '60'
    entity_id: sensor.terarium_humidity
    platform: numeric_state

next those condition conditions hard to read
my understanding is

  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: switch.hladina
      state: 'off'
    - condition: numeric_state
      entity_id: sensor.terarium_temperature
      above: 26
    - condition: time
      after: '8:00:00'
      before: '18:00:00'

to me its saying switch.hladina is off AND sensor.terarium_temperature above 26 AND time after 8:00: 00 AND before 18:00:00

looking at you logic
I dont think you need the below: 65 bit as the it only triggers when its below 60

note could be some spacing problem just winging the spacing thing ok
help this helps

OK
I need to keep the humidity between 60 and 65% during the day from 8:00 to 18:00 using the “switch.th_meter” switch in case there is enough water in the “switch.level” tank.
starting the pump at 1 hour intervals for 15 seconds is OK. Humidity does not increase immediately, so an interval of 1 hour. 15 seconds is also enough - I don’t need to have a water tank in the tria.
I have already verified this interval and it suits …

now the action bit

  action:
  - service: switch.turn_on
    entity_id: switch.th_meter
  - delay: '00:00:15'
  - service: switch.turn_off
    entity_id: switch.th_meter

bit more thinking
we need to add a other and condition
the

switch.th_meter 

MUST Be off

    - condition: state
      entity_id: switch.th_meter 
      state: 'off'

That would turn on the pump for 1:30h instead of 15s though, right?
So the delay should be 00:00:15
Or did I misunderstand something? :crazy_face:

you right just did a reread good spotting tho

1 Like

now the hard bit

the once per hour bit you want

need to look at time this automation was last run and do some maths base on the now()

thinking and doing some reading will get back.

think its going to be other and condition

remember im just wing it here someone needs to test my logic

I think it can be solved the way I wrote, either with a timer (automation triggers when timer finishes AND when humidity drops) + Condition to check for both

Or just run the script each hour (time pattern) and check for humidity :slight_smile:

there all ways more than on way to skin a cat

my idea create a template sensor
just replace the “the_automation_name” with it automation name

  - platform: template
    sensors:
      it_last_run:
        entity_id: sensor.time
        value_template: >
          {%- set time = as_timestamp(now()) | int - as_timestamp(state_attr("automation.the_automation_name","last_triggered"))  -%}
          {%- set minutes = ((time % 3600) / 60) | int -%}
          {%- set hours = ((time % 86400) / 3600) | int -%}
          {{hours}}

should return the hours it was last triggered

as it a number

    - condition: numeric_state
      entity_id: sensor.it_last_run
      above: 0

I don’t know if I understood some information correctly … :wink:

- id: '1592643427950'
  alias: rain_auto
  description: ''
  trigger:
  - at: '8:00'
    platform: time
  - at: '9:00'
    platform: time
  - at: '10:00'
    platform: time
  - at: '11:00'
    platform: time
  - at: '12:00'
    platform: time
  - at: '13:00'
    platform: time
  - at: '14:00'
    platform: time
  - at: '15:00'
    platform: time
  - at: '16:00'
    platform: time
  - at: '17:00'
    platform: time
  - at: '18:00'
    platform: time
  - at: '10:22'
    platform: time
  condition:
  - condition: state
    entity_id: switch.hladina
    state: 'off'
  - condition: and
    conditions:
    - above: 26
      condition: numeric_state
      entity_id: sensor.terarium_temperature
  - condition: and
    conditions:
    - below: 65
      condition: numeric_state
      entity_id: sensor.terarium_humidity
  action:
  - service: switch.turn_on
    entity_id: switch.th_meter
  - delay: '00:00:15'
  - service: switch.turn_off
    entity_id: switch.th_meter

Try this:

- id: '1592643427950'
  alias: rain_auto
  description: ''
  trigger:
  platform: time_pattern
    # triggers every full hour
    minutes: 0
  condition:
  - condition: state
    entity_id: switch.hladina
    state: 'off'
  - condition: numeric_state
    above: 26
    entity_id: sensor.terarium_temperature
  - condition: numeric_state
    below: 65
    entity_id: sensor.terarium_humidity
  - condition: time
    after: '08:00:00'
    before: '18:00:00'
  action:
  - service: switch.turn_on
    entity_id: switch.th_meter
  - delay: '00:00:15'
  - service: switch.turn_off
    entity_id: switch.th_meter
1 Like