Node-Red how to use input number value

I wanted to program simple automation depending on slider value (input_number) and temp sensor state.

Testing it with below flow and Im not getting expecting results:
when slider value >= temp sensor value it should be true (debug output: grater), else ‘Lower’

No matter what slider value is set it always goes ‘Lower’ path
What Im doing wrong ?

obraz

18/30 - input_number value, temp sensor = 21:

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/conditionals.html#entity-and-preventity

entity and prevEntity

Reference the entity that triggered the node.

  • entity is the current state entity
  • prevEntity is the previous state entity

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

$entities("sensor.term_salon_temp").state
1 Like

Understood i need use json for that.
will give this a try tomorrow

But still it confuses me why GUI allows to select entity from dropdown and cannot read its state…

entity is a reference to what triggered the node, basically what is in the entity id field.

In your example input_number.npiec_trigger

Sure - thanks.
But can you please advise why this doesn’t work then?

I understand Im comparing here entity (input_number.npiec_trigger) value (eg 30 or 18) to other entity (sensor.salon_temp) value (21)

In debug window I can see it takes proper input_number value, so I suspect the other part (sensor)
Ive tried to add there ‘state’ (sensor.salon_temp.state) but no difference…

Put a debug node on the first sensor with settings to complete message, then you will see what input you get from that one into the second node.
You will need to have a msg.something on your right side of the the >= equation

Sorry I afraid I dont understand what to do :frowning:

Do you mean I should add something here ?

Ive change my right side of equation to msg then my sensor and Ive got error :
obraz

1 Like

That is what you need to put in the if state box and set it to J;expression

image

1 Like

Thanks
Ive tried this one as well - but still returns false (hits ‘lower’ debug path)

After HA reboot finally started working!
Thanks Both for help!

Your flow will soon fail again.

Your first node triggers on input_number.npiec_trigger, so NodeRed gets the data from that entity.
Your second node gets input_number.npiec_trigger and compare that to a cache value of the an entity called sensor.term_salon_temp.
You flow have no reference to sensor.term_salon_temp, so you have no way to be sure it is in cache and that is the reason why it failed until you rebooted. It was not in cache, so it was unavailable and maybe considered 0.
When you rebooted some other flow ran and used that sensor and NodeRed stored the value in cache again, but it will soon purge it again.

The correct way is to have the first node as now and put a debug on it and activate the slider.
Then find the value you need to test against and copy the path with the little icon in the top right of the debug output.
Now link to the second node and put the sensor.term_salon_temp in the Entity ID field and set the if state field to compare it to msg. followed by copied path from the first node.

Thanks will try to change this as advised

Or you can enable context storage within nodered and not have to worry about losing values for any flows. Open config/node-red/settings.js. Search for

contextStorage: {
   default: {
       module: "memory"
   }
}

and replace with

  contextStorage: {
    default: "file",
    memoryOnly: { module: 'memory' },
    file: { module: 'localfilesystem' }
  },
1 Like

You will still need to read the sensor from HA to get its data into NR and you will still need to read it to get the current value and not just the last read value stored in memory/cache.

You don’t, all HA states are stored in nodered globals. When context to file is enabled globals are stored locally inside nodered and are available after a restart without connection to HA.

Ok, did not know that.
Do its states get updated too?

There is a context menu on the right. Next to the global heading hit the refresh to populate the list. Under homeAssistant are all the states it stores. Default commit is every 30sec, it can be reduced to realtime.

It’s really not necessary as this is a fallback value and is used if HA isn’t available. Also if you are using an sd it keeps the disk write down. I’m on an ssd and I use the default. The way I see it if HA is down, everything will be lagging more than 30sec anyway.

Hello everyone, not new to the home assistant but new to using node red I need help for an automation, today my atomization works as follows:

id: ligar luz do escritorio com sensor de presenca
alias: ligar luz do escritorio com sensor de presenca
description: ''
trigger:
- platform: state
  entity_id: binary_sensor.motion_sensor_escritorio
  from: 'off'
  to: 'on'
- platform: state
  entity_id: binary_sensor.motion_sensor_escritorio
  to: 'off'
  for:
    minutes: "{{ states('input_number.sensor_do_escritorio') | int(0) }}" 
action:
- choose:
  - conditions:
    - '{{ is_state(''input_boolean.ativar_sensor_do_escriorio'', ''on'') }}' 
    - '{{ trigger.to_state.state == ''on'' }}'
    - '{{ is_state(''input_boolean.horario_de_liberacao'', ''on'') }}'
    - '{{ is_state(''group.escritorio_luzes'', ''off'') }}'
    sequence:
    - service: homeassistant.turn_on
      data_template:
        entity_id:
          -  '{{ states.input_select.escritorio.state  }}'
          -  '{{ states.input_select.escritorio1.state  }}'  
  - conditions:
    - '{{ trigger.to_state.state == ''off'' }}'
    - '{{ is_state(''group.escritorio_luzes'', ''on'') }}'
    - '{{ is_state(''input_boolean.ativar_sensor_do_escriorio'', ''on'') }}' 
    sequence:
    - service: homeassistant.turn_off
      entity_id: group.escritorio_luzes

First I have the motion sensor activation, having detection it analyzes if the input_booleando of this sensor is activated, then it analyzes another boolean input that turns on when the sun sets and finally if the group to which the petence lamp is on or off. To turn it off, it takes the time from an input number and does other checks. I use this so anyone can change these variables on the wall mounted tablet I have. My difficulty is to get these conditioning variables and put them in a trigger. For example how I put the value of an input number in the wait timer field of a trigger. If anyone can help me I would appreciate it.

example 1

[{"id":"9c40722b5632bc5e","type":"server-state-changed","z":"4ae481611ef14d5e","name":"","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_sensor_escritorio","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"$entities(\"input_number.sensor_do_escritorio\").state","forType":"jsonata","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":268,"y":256,"wires":[["95fdc476820d8593"],[]]},{"id":"7b3ee86ed72260d1","type":"api-call-service","z":"4ae481611ef14d5e","name":"","server":"","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["group.escritorio_luzes"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1052,"y":256,"wires":[[]]},{"id":"95fdc476820d8593","type":"api-current-state","z":"4ae481611ef14d5e","name":"","server":"","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.ativar_sensor_do_escriorio","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":706,"y":256,"wires":[["7b3ee86ed72260d1"],[]]}]

example 2

image

[{"id":"591d93a6a9049176","type":"server-state-changed","z":"4ae481611ef14d5e","name":"","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_sensor_escritorio","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"$entity().state = off and $entities(\"input_boolean.ativar_sensor_do_escriorio\").state  = on","halt_if_type":"jsonata","halt_if_compare":"jsonata","outputs":2,"output_only_on_state_change":true,"for":"$entities(\"input_number.sensor_do_escritorio\").state","forType":"jsonata","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":280,"y":384,"wires":[["45ef65ef6bae3ed6"],[]]},{"id":"45ef65ef6bae3ed6","type":"api-call-service","z":"4ae481611ef14d5e","name":"","server":"","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["group.escritorio_luzes"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":620,"y":384,"wires":[[]]}]

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

@Sapo thank you very much, this helped me to expand my mind about nod red. Another help if you can. I have an input_select and as options it varies entities of lights. In lovelace I choose which light to turn on can this input_selec. How do I get this entity in node red? To explain better the current state of input select is the light to turn on or off