Input_number automation help

I am trying to create a simple automation to turn on a fan if the temp matches a value I want to set in the frontend.

It looks like I would use a input_number or input_select to set the value
I want the fan to come on at say 72

I already have a automation working but I have to hard code 72 and that
can change.
How do I set the value from 70-80 and pick it in the front end
and then have my automation run if it’s above that temp.

Here is my automation with the value hard coded

#----------------------------------------------
#----Turn on Fans if Indoor temp above 72

- id: fourteen
  alias: "Turn On Fans if Indoor Temp Above 72"
  initial_state: 'on'
  trigger:
    - platform: numeric_state
      entity_id: sensor.visonic_mct340_e_0b3e48b5_1_1026
      above: '72'
  condition:
    condition: state
    entity_id: device_tracker.samsungsmg935v
    state: 'home'
  action:
    - service: tts.google_say
      entity_id: media_player.ccaudio_kitchen
      data_template:
        message: >
          Inside temp warming up. Time to turn on box fan's
    - service: switch.turn_on
      entity_id:
        -  switch.wemo_mini_kitchen
    - service: switch.turn_on
      entity_id:
        -  switch.wemo_switch_1
    - service: switch.turn_on
      entity_id:
        -  switch.wemo_mini_entry

I am having a hard time with passing variables in Hassio.
Any help would be great.

trigger:
  - platform: template 
    value_template : "{{ states('sensor.visonic_mct340_e_0b3e48b5_1_1026')|int > states('input_number.YOUR_SETTING') }}" 

Whilst you’re at it you can significantly tidy up the code for your action too:

  action:
    - service: tts.google_say
      entity_id: media_player.ccaudio_kitchen
      data:
        message: "Inside temp warming up. Time to turn on box fans" 
    - service: homeassistant.turn_on
      entity_id:
        -  switch.wemo_mini_kitchen
        -  switch.wemo_switch_1
        -  switch.wemo_mini_entry
1 Like

Thanks for the quick reply.

I will try this tonight and report back.

The value_template is probably the one thing that gives me the most problems.

I kept trying

trigger:
    platform: numeric_state
    at: "{{ states('input_select.fanontemp') | int }}"

Also thanks for the tips on clean code.
I just copied them one at a time to make sure they were working
looks much better your way.

1 Like

Tried your suggestion but it’s not working.

Here is my code, do you see anything obvious?

input_number:
  fantesttemp:
    name: "Fan Test Temp"
    initial: 72
    min: 70
    max: 85
    step: 1

#----------------------------------------------
#----Turn on Fans if Indoor temp above 72

- id: fourteen
  alias: "Turn On Fans if Indoor Temp Above 72"
  initial_state: 'on'
  trigger:
  - platform: template
    value_template : "{{ states('sensor.visonic_mct340_e_0b3e48b5_1_1026') |
int > states('input_number.fantesttemp') }}"
  condition:
    condition: state
    entity_id: device_tracker.samsungsmg935v
    state: 'home'
  action:
    - service: tts.google_say
      entity_id: media_player.ccaudio_kitchen
      data_template:
        message: >
          Inside temp warming up. Time to turn on box fan's
    - service: homeassistant.turn_on
      entity_id:
        -  switch.wemo_mini_kitchen
        -  switch.wemo_switch_1
        -  switch.wemo_mini_entry

Thanks again for the help.

Copy the template in to the template editor and make sure that it resolves true/false correctly?

Look like it needed int after the input_number
I will test it out tonight.

value_template : “{{ states(‘sensor.visonic_mct340_e_0b3e48b5_1_1026’) |
int > states(‘input_number.fantesttemp’) | int }}”

I never understood the template editor but now it makes more sense.
Give a man a fish…

Thanks…

1 Like

Do triggers accept value templates now?

EDIT: They do, I was remembering something else.

1 Like

Everything is working now.
Got the template to fire true in the editor but it still was not working
I had changed my code and cleaned it up as you suggested was this

- service: switch.turn_on
      entity_id:
        -  switch.wemo_mini_kitchen
    - service: switch.turn_on
      entity_id:
        -  switch.wemo_switch_1
    - service: switch.turn_on
      entity_id:
        -  switch.wemo_mini_entry

Changed it to what was suggested

- service: homeassistant.turn_on
      entity_id:
        -  switch.wemo_mini_kitchen
        -  switch.wemo_switch_1
        -  switch.wemo_mini_entry

But it would not work.
Then I noticed you had me change from
switch.turn_on to homeassistant.turn_on
When I changed it back to switch.turn_on everything worked great.

Any reasons why you suggested homeassistant.turn_on instead?

Thanks…

switch.turn_on can only turn on switches, homeassistant.turn_on can turn on anything, so if you decide to add a light or a media player or a scene to the automation you can just tac them on the end if you use homeassistant.

Doesn’t make sense that it wouldn’t work with homeassistant.turn_on as your service.

Just changed it back to homeassistant.turn_on and it works fine now.
Must have had a spelling error or something, nice to know that works
for everything, makes doing multiple things much easier.

Again thanks…

1 Like