Automation Assistance - Newbie

Hi All,

I have setup an automation with sonoff zigbee temperature sensor and a sonof zigbee plug.

I am using Zigbee2Mqtt to connect my devices all software is up to date.

When the temperature is above a certain value it must turn on the plug that is connected to a fan.

The automation does not run automatically and if I run it manually then it turns on ignoring the temperature and condition.

I think I may be using the wrong states or something. I would really appreciate it if somebody could help,

Here is the code for my automation

- id: '1651212183531'
  alias: Garage - Turn on the inverter fan
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.garage_temperature_sensor_temperature
    above: '19'
  condition:
  - condition: device
    type: is_on
    device_id: 386743aabbeffd64ba04b17e01a17895
    entity_id: switch.garage_inverter_fan
    domain: switch
  action:
  - type: turn_off
    device_id: 386743aabbeffd64ba04b17e01a17895
    entity_id: switch.garage_inverter_fan
    domain: switch
  mode: single

That automation waits for the temperature sensor to pass from below 19°C to above 19°C. It then checks to make sure the fan is on, and if is it, switches it off. There is nothing in this code that will switch it back the other way when the temperature drops again.

That seems like the wrong way around to me, but you may have deliberately done that to work around a peculiarity of your switch.

When you run an automation manually, it is expected behaviour for it to ignore the trigger and condition, and just run the action.

Personally, I’d rewrite with entity_id instead of device for ease, although I never use the UI. This rewrite still has the on/off what I suspect to be the wrong way around:

- alias: Garage - Turn on the inverter fan
  description: ''
  id: '1651212183531'
  trigger:
    - platform: numeric_state
      entity_id: sensor.garage_temperature_sensor_temperature
      above: '19'
  condition:
    - condition: state
      entity_id: switch.garage_inverter_fan
      state: 'on'
  action:
    - service: switch.turn_off
      entity_id: switch.garage_inverter_fan

In addition to what @Troon said, '19' is not a numeric state, it is a string. Try above: 19

Thanks for the reply. So if I understand correctly then to test my automation manually I need to change the value of the temperature through the developer tool.

I think I have got confused on the condition part of the automation. If the switch is already on it should ignore the automation. I have changed based on your reply as follows:

- id: '1651212183531'
  alias: Garage - Turn on the inverter fan
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.garage_temperature_sensor_temperature
    above: '19'
  condition:
  - condition: state
    entity_id: switch.garage_inverter_fan
    state: 'off'
  action:
  - service: switch.turn_on
    entity_id: switch.garage_inverter_fan
  mode: single

This works now can you just check if am correct in my understanding, Please

You do not need to test the condition. Turning on an entity that is already on does no harm.

Ok thanks for that info :slight_smile:

And sorry yes you were right in your understanding. For a numeric_state trigger the value has to transition. And you can simulate that via developer tools.

If you create an automation with the UI, it adds the quotes for you. Ugly and inelegant, but it doesn’t matter from a functionality point of view.

1 Like