question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use variables in triggers_update

See original GitHub issue

Is your feature request related to a problem? Please describe. The triggers_update feature is great, but it only works with static text. I have some fields that I define as variables for a template, but I have to list them again under triggers_update to get the card to update with them.

Describe the solution you’d like Process variables in the triggers_update field. Listing the fields is great, but let me reference the variable, as well.

Describe alternatives you’ve considered The status quo works, but is redundant.

Additional context Here’s the template I’m working with:

control_motion:
  variables:
    motion_boolean: "input_boolean.null"
  double_tap_action:
    action: call-service
    service: input_boolean.toggle
    service_data:
      entity_id: >
        [[[ return variables.motion_boolean ]]]
  custom_fields:
    motion: >
      [[[
        if (states[variables.motion_boolean].state == 'on') { 
          return '<ha-icon icon="mdi:motion-sensor"></ha-icon>';
        } else {
          return '<ha-icon icon="mdi:motion-sensor-off"></ha-icon>';
        }
      ]]]

In my UI code, I have to list the motion_boolean field twice, both in variables and in triggers_update:

          - entity: light.stairs_hallway
            type: custom:button-card
            name: Stairs/Hallway Lights
            template:
              - general
              - inside
              - control_motion
            variables:
              motion_boolean: input_boolean.motion_light_hall
            triggers_update:
              - input_boolean.motion_light_hall

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

1reaction
ohipecommented, Jan 31, 2022

Hi, I’d like to add my 2 cents: I do an intensive use of templates in my lovelace, working extremely with variables. I have button cards with 5 icons (just icons, not nested cards) inside, each with its logics related to a specific sensor that can be built starting from the main entity of the card. So, adding these sensors as triggers in the definition of the card means loosing power of template itself. In this case, js in triggers sections may help…

0reactions
u8915055commented, Apr 3, 2022

I would just like to add that this would be very useful, even if just on the initial build of the card. Here’s my example. I have a switch that reports power usage as well. However this is all done thru tasmota and when the switch turns on and off, it takes a predefined period of time for the power usage to update (defined in teleperiod in tasmota). So if i turn the switch on as an example, the power updates in say 10-15 seconds… but by that the time state has already changed on the main entity (the switch itself) so the button card never catches the power usage update. I have the power usage displayed on the button itself. In addition, the power usage is represented by a sensor entity and i pass this entity as a button-card variable in my yaml config. Just like below:

            - type: custom:button-card
              entity: switch.topgreener2
              name: Plant Tent Grow Light
              icon: custom:ha-grow-light
              template:
                - power_reading_switch
              variables:
                secondary_info: "TopGreener Plug (Tasmota)"
                monthly_power_sensor: "sensor.tasmota_topgreener_2_energy_total"
                current_power_sensor: "sensor.tasmota_topgreener_2_energy_power"

So what happens here is switch goes on, but power still says 0W… but when i click the switch off, the button card updates to 13W, even tho the swithc is now off, because it takes ‘teleperiod’ of time to update the power usage.

What i wanted to do is use the variables defined in the button card to be the ‘triggers_update’ so when they change, the card updates. However unfortunately i cannot get it to work for reasons for which i now understand (templating a list).

This is my template config (or some of it anyway:

  power_reading_switch:
    template:
      - dimmer_cover_switch_base
    triggers_update: >
      [[[ return ['variables.current_power_sensor'] ]]]
    tap_action:
      action: call-service
      service: switch.toggle
      service_data:
        entity_id: >
          [[[ return variables.entity_id ]]]
      haptic: medium

This doesnt work but you can get the idea of what id like to accomplish. That would be my use case anyway… hope that all makes sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Set Variables in MySQL Update Trigger
CREATE TRIGGER Update_estimate_from_line_items AFTER UPDATE ON estimate_line_items FOR EACH ROW BEGIN -- variable declarations DECLARE ...
Read more >
Trigger variables (PL/SQL) - IBM
Trigger variables (PL/SQL) · NEW is a pseudo-record name that refers to the new table row for insert and update operations in row-level...
Read more >
Local Variable in UPDATE() T-SQL Trigger Function
I am trying to use the UPDATE() Trigger Function for local variable @fieldname. The goal is this way I am only comparing the ......
Read more >
SQL Server trigger with variable - YouTube
For queries contact on gamerstrings20@gmail.comGOALTER TRIGGER [dbo].[trigger1] ON [dbo].[tab1]for insertASdeclare @counts intBEGINselect ...
Read more >
Trigger Context Variables | Apex Developer Guide
Trigger Context Variables ; old, Returns a list of the old versions of the sObject records. This sObject list is only available in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found