Automation: Starting a scene depending on sensor value

Hello.

I’d like to achieve the following. I set a sensor value from a physical KNX switch. Depending on the sensor value I’d like to start a HA scene.

So I thought I will simply have a new HA automation that reacts on the sensor value being on a numeric state between 0 and 255. Depending on the value I’d like to start a different scene.

At the moment I got:

alias: Start HA scene from KNX sensor value
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.knx_to_homeassistant_szene
    above: '0'
condition: []
action:
  - service: scene.turn_on
mode: single

And now I don’t get how to start different scenes depending on the sensor value in one automation. I don’t like to have different automations for each value.

What is the right way to achieve that?

Thank you very much!

Denis

Try

trigger:
  - platform: state
    entity_id: sensor.knx_to_homeassistant_szene
    to: ~

That will trigger whenever the state changes, and then you can use a choose to pick what to do.

For some reason numeric_state wont accept a single value.
I “fixed” this for myself by doing that bit in yaml:

condition: state
entity_id: sensor.meerlanden_gft
state: 1
attribute: Days_until

I created the state in the GUI and then entered into yaml mode and removed the ’ from the number
‘1’ → 1

I’d use a knx_event instead of a sensor entity to trigger it. Then choose based on "{{ trigger.event.data.data == 1 }}" or "{{ trigger.event.data.value == 1 }}" key for value 1 (knx scene 2 if you use DPT 17).

Thank you for the hint. Arghs I had the event but did let me distract by the cookbook which used sensor values for switching some hue bulbs.

Ok I will try the events again.

Am I right that you would have the following flow:

  • Define KNX Event in the knx integration for the DPT 17 GA (which gets set by the Glastaster)
  • Have a automation which reacts on this above mentioned KNX event
  • The automation triggers a script and the script chooses a scene depending on the sent value

Is this correct?

I will try to implement that one. As a beginner it is a bit hard to get into it. :slight_smile:

Yes seems right. Except that the automation triggers the scene directly in its action via a choose, not a script.

I’d stick to HAs automation/script/template documentation - there has been lots of changes recently that make things simpler. You won’t find those in old forum posts.

1 Like

Ok so this is working like charme now:

alias: Starte HomeAssistant Szene auf Basis von KNX Szene
description: Startet eine Szene basierend auf dem von KNX übergebenen Szenen Wert
trigger:
  - platform: event
    event_type: knx_event
    event_data:
      destination: 0/3/1
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.value == 1 }}'
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.bad_baden
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.value == 2 }}'
        sequence:
          - service: scene.turn_on
            target:
              entity_id: scene.bad_chillout
mode: single