Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Automations from text sensor #2

Open
dakweenduck opened this issue Nov 25, 2023 · 6 comments
Open

Automations from text sensor #2

dakweenduck opened this issue Nov 25, 2023 · 6 comments

Comments

@dakweenduck
Copy link

Hi ,

Thanks for this integration it's really useful.

What seems like a simple issue I just cant spot it and probably will slap myself:) . Since the text sensors don't update the latest value to HA if different to previous I'm trying to use using a 'event' to to do this to use in HA automations:

Here is the code:

      - id: presence_sensor
        name: "internal_presense_sensor_to_binary_template"
        internal: false
        on_value:
          - binary_sensor.template.publish:
             id: presence_template
             state: !lambda return x == "on";

          - homeassistant.event:
               event: esphome.face_recognition_scan_matched
               data:
                  title: Test Presense
               data_template:
                 user_id: User ID is {{ my_variableha1 }}
                 reply:   Reply is {{ my_variableha2 }}
                 presense: Presense is {{ my_variableha3 }}
                 presense2: Presense is {{ my_variableha4 }}

               variables:
                 my_variableha1: |-
                       !lambda 'return user_id_template;'
                 my_variableha2: |-
                       !lambda 'return reply_template;'
                 my_variableha3: |-
                       !lambda 'return x;'
                 my_variableha4: |-
                       "{{ states.presence_template.state }}"

The event is firing but the value passed in data template is the lambda command string and not value:)

event_type: esphome.face_recognition_scan_matched
data:
  device_id: d3dff94d2e3789efe17dbc18fbce28e9
  title: Test Presense
  user_id: User ID is !lambda 'return user_id_template;'
  reply: Reply is !lambda 'return reply_template;'
  presense: Presense is !lambda 'return x;'
  presense2: Presense is "{{ states.presence_template.state }}"
origin: LOCAL
time_fired: "2023-11-25T04:03:30.982517+00:00"
context:
  id: 01HG2AB6H6CWFZ1DJ9TXPXP1RW
  parent_id: null
  user_id: null
@Chreece
Copy link
Owner

Chreece commented Nov 25, 2023

What you mean by that? The Text Sensor got new values and doesn't show them?

Since the text sensors don't update the latest value to HA if different to previous

@dakweenduck
Copy link
Author

None of these 3 values update if the Old state is equal to the New State.

Presence
Responce
User ID

For example ID0 get a successful match now and a few seconds/minutes/hours later ID0 gets another match this is not updated. If a new match is received for ID1 for example then the update happens immediately.

Their also seems to be no option for "force_update" for a "text_sensor" only "binary sensor" in esphome to update state when one is received regardless of the current value.

Without getting an indication that the a state was received I see no way to create automations in HA other than using "events", or am I missing something?

Face_ID_NO UPdate2023-11-25 160504

@Chreece
Copy link
Owner

Chreece commented Nov 26, 2023

I haven't practically used my code. Just made it to help others.
When someone recognised binary sensor Presence is turned on.
So you should use the binary sensor to monitor face recognitions, not the text sensor.
Please inform me if that works for you

@dakweenduck
Copy link
Author

Neither of the 3 were working.

Managed to get it working for all 3 by setting a default state after a response is received. Can now create various automations by using all 3 states . Without "userID" or the "Response" it is limited as Time Based conditions or other scenarios are not possible.

Would have preferred using events and might look at it again but for now this works. If someone has an idea what the issue could be with events as per the intro that would be great to know.

text_sensors:
  - id: text_userid
    name: "internal_text_userid_to_text_template"
    internal: true
    on_value:
       then:
          - text_sensor.template.publish:
              id: user_id_template
              state: !lambda return x;

          - delay: 2s

          - text_sensor.template.publish:
              id: user_id_template
              state: !lambda return {"waiting"};


  - id: text_reply
    name: "internal_text_reply_to_text_template"
    internal: true
    on_value:
       then:
          - text_sensor.template.publish:
              id: reply_template
              state: !lambda return x;  

          - delay: 2s

          - text_sensor.template.publish:
              id: reply_template
              state: !lambda return {"waiting"};


  - id: presence_sensor
    name: "internal_presense_sensor_to_binary_template"
    internal: true
    on_value:
       then:
          - binary_sensor.template.publish:
             id: presence_template
             state: !lambda return x == "on";

          - delay: 2s

          - binary_sensor.template.publish:
             id: presence_template
             state: off

@dakweenduck
Copy link
Author

For anyone interested I have designed a case for this:

https://www.thingiverse.com/thing:6320616

@Chreece
Copy link
Owner

Chreece commented Nov 28, 2023

Great Design, thank you for sharing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants