Simple String Match

I will confess, lambda is not my strong point, and coding in yaml is a close second. Here’s a peice of code I have been working on a for a few days. I am close… really close. Except I cannot figure out the lambda code to match the text string.

All I need to do is figure out a way to confirm the entity value is either ‘home’ or ‘not_home’ that’s it. I have been attempting to trial a few approaches for too many hours… so any ideas appreciated.

text_sensor:
  - platform: homeassistant
    name: “Galaxy S10”
    id: galaxy_s10
    entity_id: device_tracker.galaxy_s10
    update_interval: 60s
    discovery: true
    internal: true
    on_value:
        then:
        - if:
            condition:
              # Test if state is 'not_home'
                    - lambda: ##some code to check if string matches ‘not_home’##
            then:   
                   - binary_sensor.template.publish:
                         id: S10_status
                         state: off
        - if:
            condition:
               # Test if state is 'home'
                   - lambda: ##some code to check if string matches ‘home’##
            then:
                   - binary_sensor.template.publish:
                          id: S10_status
                          state: on

Try this:

    on_value:
        then:
        - if:
            condition:
              # Test if state is 'not_home'
                    - lambda |-
                        return id(galaxy_s10).state == 'not_home';
            then:   
                   - binary_sensor.template.publish:
                         id: S10_status
                         state: off

One thing though, there’s no point enabling discovery if it is an internal component.

    discovery: true # why?
    internal: true

Hi Tom,

Apology for not coming back sooner. No excuse. Managed to get things working based upon your feedback. Thank you very much.

Mark

1 Like