BRUH DIY Multisensor

Hi, currently I did a very very very simple merging of both scripts and it has been working great for the last month or so (I use only the IR part of the 1technophile gateway, but I assume the rest works as well).
I am a complete noob with arduino IDE and programming an ESP, so I basically created a function like the ZgatewayIR.ino or ZgatewayRF.ino that it called ZgatewayBRUH.ino, then added the good functions in the main loop and voilà. However, the code is not elegant at all, I want to make sure I understand everything in order to make it a bit more cleaner before sharing it in full.

Currently, the multisensor I have is:
ESP8266 powered by micro USB, and small breadboards in order to connect everything to ground and 3v3 or Vin

  • PIR sensor
  • Light Sensor
  • RGB Led
  • DHT22
  • IR receiver
  • 2 IR emitter (and a transistor to boost the current trough them)
1 Like

I might give it a go during the weekend then!
I have been just playing around with all the different sensor modules I bought in hopes of learning how to program on Arduino or at least a better understanding of it.

Might be a silly question but can I connect a breadboard to pin A0 and use multiple sensors from it?

Hi

Can you please share your automation code for controlling the fans if the temp is above X.

Thanks.

Thanks I discovered it was the faulty usb cable giving me issues. All sorted now.

1 Like

I haven’t set it up for the kids rooms yet, I need some cases before I put anything in their rooms. But I do have it set up from the AC. It’s portable unit that retains it’s state when unplugged so I was able to use a z wave appliance module to turn it off an on.

Nothing to fancy, only comes on if the temp is 25 or above, we are home and only between certain hours of the day.

alias: Turn on Air Conditioner
trigger:
  - platform: numeric_state
    entity_id: sensor.sn1_temperature
    above: 25
condition:
  - condition: state
    entity_id: input_boolean.presence
    state: 'on'
  - condition: time
    after: '9:00:00'
    before: '22:00:00'
action:
  - service: switch.turn_on
    entity_id: switch.leviton_dzpa11lw_plugin_appliance_module_switch

Edit: I’ve been thinking about adding in some predictability to it. Say if the outside temp is expected to be above X today, start the AC prior to the room reaching 25 degrees. Just to give the AC a jump start on cooling. I haven’t worked out how yet but I’m sure it’s probably fairly straight forward.

2 Likes

I was trying this project again since I made some other sensors successfully based on this code and I had the idea of looking through the github forks because I discovered when re-using the code there was a lot of room for improvements. I found this code which looks like it might be a big improvement. I don’t suppose someone has tried it?

So I am trying to turn my kitchen lights on when the temperature is above 18 degrees celsius, here is my code:

- alias: Temperature above 18 degrees celsius turn on Kitchen Lights
  trigger:
    platform: numeric_state
    entity_id: sensor.sn1_real_feel
    above: 18.0
  action:
   service: switch.turn_on
   entity_id:
    - switch.kitchen_lights

the automation seems to be working when I trigger it from the front end, however 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.

Am I missing something?

I believe 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.

Change your “above” temp to something higher then the present room temp and then try to trigger it by blowing on the sensor to raise the temp. This worked for me in testing. Someone smarter then me can probably tell us if there’s way to code it so it fires if the temp is already above the set point automatically. This would be case if you restarted HA and the temp was above the set point for instance. Similar to a Sunset trigger won’t fire at 2am.

I’m just learning myself so anyone feel free to correct me.

Right I see.

Did you mean I should raise my numerical “above” value of the temperature?

Try this:

  trigger:
    platform: template
    value_template: >
         {% if states.sensor.sn1_real_feel > 18 %}
              true
         {% endif %}
2 Likes

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