BRUH DIY Multisensor

so I tried the code you gave me, here is mine:

- alias: Temperature above 18 degrees celsius turn on Kitchen Lights
 trigger:
   platform: template
   value_template: >
        {% if states.sensor.sn1_real_feel > 18 %}
             true
        {% endif %}
   action:
   service: switch.turn_on
   entity_id:
    - switch.kitchen_lights

I get errors:

2017-07-30 17:07:44 ERROR (Thread-2) [homeassistant.util.yaml] while parsing a block mapping
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 451, column 2
2017-07-30 17:07:44 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/homeassistant/.homeassistant/configuration.yaml: while parsing a block mapping
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "/home/homeassistant/.homeassistant/configuration.yaml", line 451, column 2

Align your spaces :wink: looks like you need to add about 2 more spaces to each line at the begining

1 Like

right so I got it working but I have the same issues as earlier i.e. it doesn’t work when the temperature goes above 18 degrees celsius because at present the temperature is above 19.5 and it doesn’t seem to turn the Kitchen Lights on.

and here is my code:

- alias: Temperature above 18 degrees celsius turn on Kitchen Lights
  trigger:
    platform: template
    value_template: >
         {% if states.sensor.sn1_real_feel > 18 %}
              true
         {% endif %}
  action:
   service: switch.turn_on
   entity_id:
    - switch.kitchen_lights

any idea?

The template is wrong, it shoud be

{% if states.sensor.sn1_real_feel.state | float > 18 %}
  true
{% endif %}

Note that the ’ | float ’ is only necessary if your sensor send data as a string and not as a numeric (which is the case using Ben’s code I think).

Note also that there is a template utility in development tools on the frontend. You can type in your template in this utility and directly see the result, so you can mess around freely and change it to suit your needs. Here is a screenshot of the test I just did

However, I think that using this automation like that, your fan will always be turning on as soon as long as the temp is > 18; even at night, even when no one is home. So you may want to put some conditions to limit it and save some money on the electricity bill. :wink:

2 Likes

nice, I was looking for something similar ! I will definitely check that next week !

does your template action straight away i.e. if the temperature is greater than 18, would it turn the e.g. lights right away? because like @SeveredDime mentioned:

it’s because the automation doesn’t technically trigger because the temp is already above the set point when you started. The temp didn’t go from 17.9 to 18.0. so it doesn’t fire.

Oops missed the last attribute :stuck_out_tongue:

It’ll throw a true so as long as your conditions are met it should technically turn on as soon as it’s over 18, even if the sensor starts at 19.

The template trigger will always be true as long as the temp is above 18 (even if it is already above 18 when you restart HASS). Meaning that if for some reason you manually turn off the switch, the automation will directly turn it on if the temp is still > 18. (which may be annoying).

That is the difference with numeric_state above 18. In that second case, the trigger will turn true when the temp goes from under 18 to 18 or more. So it triggers only when the threshold is crossed.

nope its a shame the temperature is 18.2 now and the template trigger is not true it seems, here is my code:

- alias: Temperature above 18 degrees celsius turn on Kitchen Lights
  trigger:
    platform: template
    value_template: >
         {% if states.sensor.sn1_real_feel.state | float > 18 %}
           true
         {% endif %}
  action:
   service: switch.turn_on
   entity_id:
    - switch.kitchen_lights

here is my working automation:

# turn on ac if temp is 30 or above 30 
  - alias: 'AC on If Temp >= 30'
    initial_state: True
    trigger:
      - platform: template
        value_template: '{{ states.sensor.sn1_temperature.state | float >= 30}}'
    action:
      service: switch.turn_on
      entity_id: switch.ac
3 Likes

Awesome, the people smarter than me showed a better way :slight_smile: I’ll be changing my automation.

1 Like

are you using BRUH’s DIY Multisensor to sense the temperature?

also could you elaborate on “initial_state: True” sorry I am a noob.

Does your automation fire everytime the temperature is above 30? The code you provided does work for me but once 5mins after I restart HA.

Is yours the same?

Yes, I am using BRUH’s Multisensor.

As of version 0.42 you have to set an initial state in your automations in order for Home Assistant to restore them upon restart.

I have 2 automation:

  1. when temp is 30 turn on ac and turn off fan.
  2. when temp is 24 turn on fan and turn off ac

and its working fine.

I am also a noob, the automation code provided by @lambtho

Thanks again @lambtho

2 Likes

I received MQ-135 sensor today and uploaded your sketch successfully but it showing airquality value “705.52” all the time.

I had wrong values with MQ-2 sensor plugged to the PC everything was solved when I plugged into the wall instead.

but in my case value is fixed 705.52 no up and down even I have plugged with a wall adapter.

It’s been recommended to leave the sensor on for 24 hours to allow it to ‘burn-in’.

okay, will do that and let you know about result.

Thanks

I tried contacting him to get his yaml files for HASS but I wasn’t able to find his contact info. It looks a lot cleaner.

It looks like the data comes out like this:

homeassistant/sensor/sensornode3_sensor_temp/state 79.16
homeassistant/sensor/sensornode3_sensor_humidity/state 41.70
homeassistant/binary_sensor/sensornode3_sensor_pir/state OFF

Yes, that is what I understood from looking upon the code… Seems nice