Simple De/Humidifier Control

I’m very new to node-red. I’m wanting to make a simple humidity control. I’d prefer not to use a function node for the logic, but rather individual nodes. That way I can follow the flow more visually.

The logic would be the same as this automation I created in HA (currently it’s set up for dehumidifying. I use the same switch and change it based on the season but don’t change the entity name, thus the switch name, “switch.humidifier_1_switch”):

- id: master_bedroom_humidity
  alias: Master Bedroom Humidity
  trigger:
  - platform: state
    entity_id:
    - input_number.master_bedroom_humidity_setpoint
    - sensor.master_bedroom_humidity
  action:
  - service_template: "{% set hi = (states('input_number.master_bedroom_humidity_setpoint')\
      \ | float) + 0 %} {% set lo = hi - 0 %} {% set humidity = states('sensor.master_bedroom_humidity')\
      \ | float %} {% if humidity > hi %}\n  switch.turn_on\n{% elif humidity < lo\
      \ %}\n  switch.turn_off\n{% else %}\n  switch.turn_{{states('switch.humidifier_1_switch')\
      \ | lower}}\n{% endif %}"
    entity_id: switch.humidifier_1_switch
  mode: single

I’ve tried several combinations but I can’t seem to figure out a way to get node-red to use the input-number from HA, “input_number.master_bedroom_humidity_setpoint”, as a variable. Maybe it’s not possible? :man_shrugging:t4:

[{"id":"bb881b95.6626c8","type":"server-state-changed","z":"d4450f17.60952","name":"Triggers","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.master_bedroom_humidity_setpoint, sensor.master_bedroom_humidity","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":140,"y":680,"wires":[["b1bb8a0e.5acab8"]]},{"id":"b1bb8a0e.5acab8","type":"api-current-state","z":"d4450f17.60952","name":"Get hi","server":"9405c3fe.d0a6c","version":1,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"input_number.master_bedroom_humidity_setpoint","state_type":"num","state_location":"hi","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":true,"x":270,"y":680,"wires":[["f3f2fca6.a3e93"]]},{"id":"f3f2fca6.a3e93","type":"api-current-state","z":"d4450f17.60952","name":"Get humidity","server":"9405c3fe.d0a6c","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.master_bedroom_humidity","state_type":"num","state_location":"humidity","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":true,"x":410,"y":680,"wires":[["d20ca2e7.f743f"]]},{"id":"d20ca2e7.f743f","type":"api-current-state","z":"d4450f17.60952","name":"Get switch current state","server":"9405c3fe.d0a6c","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.humidifier_1_switch","state_type":"str","state_location":"currentState","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":true,"x":610,"y":680,"wires":[["9b64aa8d.01d728"]]},{"id":"9b64aa8d.01d728","type":"change","z":"d4450f17.60952","name":"Set lo & + 0 ranges","rules":[{"t":"set","p":"hi","pt":"msg","to":"$number(hi) + 0","tot":"jsonata"},{"t":"set","p":"lo","pt":"msg","to":"$number(hi) - 0","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":680,"wires":[["c853897b.c62ee8"]]},{"id":"c853897b.c62ee8","type":"switch","z":"d4450f17.60952","name":"","property":"humidity","propertyType":"msg","rules":[{"t":"gt","v":"hi","vt":"msg"},{"t":"lt","v":"lo","vt":"msg"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":990,"y":680,"wires":[["8677fe.a9ed78"],["e3ce0df4.981d6"],["ef393185.e3a3a"]]},{"id":"8677fe.a9ed78","type":"api-call-service","z":"d4450f17.60952","name":"Switch on","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"switch.humidifier_1_switch","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1140,"y":640,"wires":[[]]},{"id":"e3ce0df4.981d6","type":"api-call-service","z":"d4450f17.60952","name":"Switch off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"switch.humidifier_1_switch","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1140,"y":680,"wires":[[]]},{"id":"ef393185.e3a3a","type":"api-call-service","z":"d4450f17.60952","name":"keep","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_{{currentState}}","entityId":"switch.humidifier_1_switch","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1130,"y":720,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

I hope that works, I cannot test it. Why do you want the “+ 0”? I guess you’ll change that with other number? to set the range from going on to off?

1 Like

Dang, that was fast. Lol thanks!

I’ll test it tomorrow. Yes, it’s for the hysteresis value (If that’s the correct terminology).

I’m gonna explain a little bit since you are very new to NR.

Node Triggers:

Setting Substring allows to put a comma separated string of entities. I left the if state blank on purpose so the flow will trigger with any state changed of any of those entities.

Node Get hi:

I left if state blank so the flow always continues regardless of the state. It stores the state of the entity in msg.hi as you can see in the bottom.

Nodes Get humidity and Get switch current state:

Same as the last one.

I believe the rest is fairly obvious. Ask if you don’t understand something

1 Like

Works like a charm! I made a few changes to the message properties to ensure I understood what was happening. After adding a few debug nodes it makes perfect sense.

I can’t remember why I put

  {% else %}
    switch.turn_{{states('switch.humidifier_1_switch') | lower}}

in my original automation; if I even had a reason. :grimacing: I cobbled that together from about 5 different examples I found online and never really understood it completely.

That’s the equivalent of the “Get switch current state” and “keep” node, correct? I suppose they don’t really serve a purpose if I understand it correctly. Or am I missing something?

Exactly, that’s the equivalent. Depending on how you build your automation/flow, the majority of the times you can skip that. It’s like telling the switch that when lo < humidity < hi, do nothing, or stay as you are, on if on, off if off. It won’t hurt to have that there though.

If there were more triggers, like windows or doors, it would be a good idea to implement what to do within that humidity range.

Gotcha. Learned a lot, thanks! You da man.