MarkAdamson / home-assistant-plugin-for-tasker

Home Assistant plugin for Tasker

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GetState device its "brightness" attribute

nlafleur opened this issue · comments

Having a problem receiving the "brightness" of my light in my bedroom.
I'm trying to create a wake-up light so I created a task "check alarm", which checks my alarm and sets this value as a variable, this also checks the alarm -14 minutes.

So 14minutes before my alarm goes off it will turn on my nightstand light, preferably with the lowest brightness, then, every 2 minutes (from AlarmTime to AlarmGo in tasker) it will run a task.

I want to create a task that;
checks the current brightness of my nightstand light,
increase the brightness of this value.

I tried to get the brightness value like this:
in tasker > plugin > home assistant plugin > "Get State" > filled in my server info, the Entity ID and I set the variable to %slaapkamerspotlinksbrightness, with the attribute "brightness", but this returns "on" or "off", depending on the device its status.

And even I this would return the brightness level, how do I increase it?

Hey, surprisingly tricky one this. The Get State action returns the overall state of the light (on or off), and optionally the full set of attributes, which is a long json string including brightness (if the light is on). You could do some finagling within Tasker to extract the brightness from the attribute string, but it's not ideal. You'd be better off rendering a template.

I recommend learning to use template rendering in Home Assistant. There are good examples and documentation under 'Developer Tools' > 'Template', but briefly, this is how you do it:

  1. Add a 'Render Template' action.
  2. In 'Template', enter:
    {% if state_attr('light.my_light', 'brightness') == None %}0{% else %}{{state_attr('light.my_light', 'brightness')}}{% endif %}
  3. In 'Variable' enter:
    %brightness

Remember to replace 'light.my_light' in the template text with your own light's entity_id (twice). %brightness will now contain the current brightness (from 0 - 255). Increase it by whatever you like using a 'Variable Add' action, then set the brightness like so:

  1. Add a 'Call Service' action.
  2. In 'Service' enter:
    light.turn_on
  3. In 'Service Data' enter:
    {"entity_id": "light.my_light", "brightness": %brightness}

Again, remember to replace 'light.my_light' in the service data with your own light's entity_id - and that should be it.