Set helper to value of sensor

How can I set a helper to the value of a sensor (e.g. binary or number)?

service: input_number.set_value
  value: {{ states('sensor.test')|int }}
  entity_id: input_number.fehler_test

This does not work, also I am not sure about boolean helpers.

The template is missing outer quotes.

service: input_number.set_value
  value: "{{ states('sensor.test')|int(0) }}"
  entity_id: input_number.fehler_test
1 Like

That was it. :slight_smile:

How can I do this for input_booleans? There is only a service for turn on/off, but not set to value.

What value do you want to set? An input_boolean only has two values (on/off).

I found it, thanks :slight_smile:

- service_template: "input_boolean.turn_{{ states('binary_sensor.regenl')}}"
  entity_id: input_boolean.fehler_regen

For future reference, service_template was deprecated in favor of service many versions ago.

Your previous stated requirement was confusing to me because an input_boolean only has two values and it’s set with the turn_on and turn_off services.

What is the application you have for setting an input_boolean’s state to be the same as a binary_sensor’s state?

I need both numbers and booleans. The requirement originated from this issue here:

I found a solution without the need for these helpers.

But for reference I just want to know: How can i set an input_boolean to the state of a binary_sensor?

How is this useful? You’d use an input boolean because you want to be able to set the state, but if the input always has the value of the sensor, what is there to change? On the other hand, you could have a sensor that reflects the value of the input to make it a kind of read-only value, but even in this case one could just use the input directly.

Anyway, to do it you will need to make an automation that triggers on the sensor’s state change and then call the appropriate service.

Glad to hear it solved the problem.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.