Raw status codes from a sensor

To interact on the is_state a sensor sends I need to know the raw status codes. If you are more expercienced, can you tell me where I’ll find the raw code/name a sensor sends like sun.sun and above_horizon?

        value_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            Day
          {% else %}
            Night
          {% endif %}
        icon_template: >-
          {% if is_state('sun.sun', 'above_horizon') %}
            mdi:weather-sunny
          {% else %}
            mdi:weather-night
          {% endif %}

What do you mean with “raw status codes”? Do you want to know all the possible states for the sun.sun sensor?

As you will know a sensor sends the status and uses “sun-sun” or so. I only need to know which state name/text is used so I can fill in after if_state(…) in the democode above.

You can find that all listed here listed under State Attributes.

I’m sorry I don’t get it. Could you please explain what you want to do exactly?

In your example … if is_state(…), sun.sun is the sensor and above_horizon is the state.

Your link is wrong. It redirects to the latest forum topics…

Sorry if I am not clear, English is not my native language. I have to fill in the status sent by the sensor on the dots to take further action. The problem is that I cannot find what I have to enter there, in other words, what exactly the sensor sends. That is why I am looking for a way to see which status messages a sensor sends.

No worries, English is also not my native language :wink: This depends on the sensor. For the sun integration the states are “above_horizon” and “below_horizon” as you can see here:

Maybe you can explain what you want to do and then I might be able to help you.

Thanks for understanding :wink: The sensor is a Philips Hue motion sensor, integrated in Hassio by using a so called integration. Therefor the settings are also no part of configuration.yaml by default.

Then you probably have a binary sensor something like binary_sensor.motion_sensor_batroom.
The possible states for a binary sensor are “on”, “off” or “unavailable”, where “on” means “motion” and “off” means no motion, as you can read in the below link.

I was searching for messages like “detection” and “no-detection” and will try “on” and “off” now, thanks!

No succes with the code below so any suggestion is welcome.

sensor:
  - platform: template
    sensors:
      binary_sensor_trap_sensor_motion:
        friendly_name: "Trap"
        value_template: >-
          {% if is_state('off') %}
            geen
          {% else %}
            beweging
          {% endif %}

You did not specify the sensor in your is_state(..

What is the entity_id of you binary sensor? Is it binary_sensor.trap_sensor_motion?

In the below example the name of the binary sensor is binary_sensor.motion_bathroom

sensor:
  - platform: template
    sensors:
      binary_sensor_trap_sensor_motion:
        friendly_name: "Trap"
        value_template: >-
          {% if is_state('binary_sensor.motion_bathroom', 'off') %}
            geen
          {% else %}
            beweging
          {% endif %}

Thanks for your help, everything works fine now. For those who have the same issue with Philips Hue motion detector, this is the working code in my config file:

sensor:
  - platform: template
    sensors:
      binary_sensor_trap_sensor_motion:
        friendly_name: "Trap"
        value_template: >-
          {% if is_state('binary_sensor.trap_sensor_motion', 'on') %}
            beweging
          {% else %}
            geen beweging
          {% endif %}

Whew! This is a rather long thread to ultimately discover the goal was to translate a binary_sensor’s on/off states to beweging/geen beweging (movement/no movement). :slight_smile:

Simply defining the device_class:
device_class: motion
will cause the binary_sensor to display (in the UI) motion-related states (Detected/Clear as opposed to on/off). It will also change the appearance of the sensor’s icon.

If you don’t like Detected/Clear (or whatever the translation is for your native language) then you’ll need to create a Template Sensor to perform the conversion.

Yeah I’m not that good at understanding people’s requests :joy:

Once again you provided an easier solution, maybe I should just wait for your reply the next time :crazy_face: I didn’t even think about this, was too focused on fixing the template.

All things considered, I think you did very well. It’s challenging, for everyone involved, when they must communicate in a non-native language. I can’t even imagine attempting to participate in a Dutch-language forum. I’d have to resort to using Google-translated messages … and that would hardly make things easier for native Dutch speakers to interpret my meaning.

Ooops…fixed now.