Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable property to update with track #14

Closed
wants to merge 3 commits into from
Closed

Configurable property to update with track #14

wants to merge 3 commits into from

Conversation

nagyrobi
Copy link
Collaborator

to be able to update not just "val" but anything else

add update propery config entry
update property added
Add update_property to example conf
@nagyrobi
Copy link
Collaborator Author

For #7

@dgomes
Copy link
Collaborator

dgomes commented Mar 17, 2021

Thanks for this PR :)

I was actually planning in having the possibility to link entities to various properties:

      - obj: "p1b3" #This is a checkbox
        text: {{ state_attr('automation.rise_and_shine', 'friendly_name') }}
        val: {{ state('automation.rise_and_shine') }}

@nagyrobi
Copy link
Collaborator Author

Ok I was just trying to do something :-)

@nagyrobi nagyrobi closed this Mar 17, 2021
@dgomes
Copy link
Collaborator

dgomes commented Mar 17, 2021

Highly appreciated! :)

@nagyrobi
Copy link
Collaborator Author

I would give it a shot if you'd point me into the right direction on how to expand the template into a result variable.

@nagyrobi nagyrobi reopened this Mar 17, 2021
@dgomes
Copy link
Collaborator

dgomes commented Mar 17, 2021

I always find it easier to look into existing components that already support the feature I want to implement and learn from their implementations.

Here is a very simple component that uses templates: https://github.com/home-assistant/core/blob/0e98bc5ea23cd15ecdc17a8318250b4a8fbe9478/homeassistant/components/rest_command/__init__.py

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

Major refactor yesterday, please have a look

@nagyrobi
Copy link
Collaborator Author

nagyrobi commented Mar 21, 2021

Nice, I see the # TODO support more then "val" at async_listen_state_changes.
Wonder if I add the template to variable resolver above in __init__ would that be enough or should it be pushed down in async_listen_state_changes to receive updates regularly?

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

I'm afraid that will not be enough, tonight I might have some extra time to try and address this

@nagyrobi
Copy link
Collaborator Author

nagyrobi commented Mar 21, 2021

I think to add a configurable, optional val_factor parameter to the obj section which would be useful to address this.
The arc in hasp-lvgl can only handle integers, so you need to set it to move between 150 and 300, and divide by factor 10 to obtain decimal values to set a target temperature in Home Assistant between 15.0 and 30.0 degrees.

  • But you need to multiply back with 10 when you update the val of the arc.
  • And you need not to multiply with anything when updating other properties like value_str.

So val_factor parameter would be only involved in reading (divison) and setting (multiplication) of the val property.
Of course only makes sense for numeric values.

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

a1f5704 implements this

@dgomes dgomes closed this Mar 21, 2021
@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

you can type any conversion you wish into the template to set the hasp objective property, now I'll work on the event side

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

Done in 4795760
event service call can now use variables (MQTT messages key/values) in their service templates

@nagyrobi
Copy link
Collaborator Author

event service call can now use variables (MQTT messages key/values) in their service templates

What's the syntax? For MQTT message sent by the plate: {"event":"changed","val":110} how do I extract the val?

To achieve something like this:

        event:
          "changed":
            service: climate.set_temperature
            data_template:
              entity_id: climate.futes
              temperature: "{{ val / 10 }}"

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

temperature: "{{ val | int / 10 }}"

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

also you don't need "data_template" it's just "data"... you can test the service call in developer-tools/server and then copy & paste to the configuration.yaml

@nagyrobi
Copy link
Collaborator Author

Excellent.
try:
{"obj":"arc","id":3,"x":20,"y":75,"w":200,"h":200,"min":120,"max":460,"border_side":0,"type":0,"rotation":0,"start_angle":135,"end_angle":45,"start_angle1":135,"end_angle1":45,"value_font":28,"value_color":"#2C3E50","adjustable":"true"}

and

      - obj: "p2b3"
        properties:
          "val": "{{ state_attr('climate.climate1','temperature') * 10 | int }}" 
          "value_str": "{{ state_attr('climate.climate1','temperature') }}" 
        event:
          "changed":
            service: climate.set_temperature
            data:
              entity_id: climate.climate1
              temperature: "{{ val | int / 10 }}"

@nagyrobi nagyrobi deleted the patch-3 branch March 21, 2021 19:32
@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

does it work or not ?

You should join the hasp-lvgl discord ;)

@nagyrobi
Copy link
Collaborator Author

it works but it needs some throttling

@dgomes
Copy link
Collaborator

dgomes commented Mar 21, 2021

can't do much from HA side... if the events are generated, they are being processed

@nagyrobi
Copy link
Collaborator Author

nagyrobi commented Mar 22, 2021

There's a race causing this:
https://user-images.githubusercontent.com/1550668/112021864-05640a00-8b32-11eb-80f0-20a17051770c.mp4

I think what happens is:

  • I drag the arc, object changed
  • plate sends an MQTT
  • HA gets it as event -> component adjusts the entity
  • entity has changed -> component sends MQTT
  • plate gets it as update command -> adjusts the arc, object changed
  • and goto line 1 again....

So what should be done perhaps is to avoid setting the val property, when the update of the component was triggered by a val change from the same device/object...

@nagyrobi nagyrobi mentioned this pull request Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants