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

data_template and integer #7

Closed
Mace404 opened this issue Aug 13, 2018 · 6 comments
Closed

data_template and integer #7

Mace404 opened this issue Aug 13, 2018 · 6 comments

Comments

@Mace404
Copy link

Mace404 commented Aug 13, 2018

Hi,

First on, great work on the script.
All the services are working great when I call them manually or with a script using a static value.

I added a light template for my Dreamscreen and most of it works great (Detects current status, can turn it on and off).
The thing I'm running in to is that data_template always outputs a string (because that is what Jinja does) and because of that I cannot use data_template to use any form of logic.

I'm using this on my light entity to set brightness:

  set_level:
    service: dreamscreen.set_brightness
    data_template:
      entity_id: dreamscreen.dreamscreen_4k
      brightness: "{{ (brightness / 2.55) | int }}"

and this gives the following error:
ERROR (MainThread) [homeassistant.core] Invalid service data for dreamscreen.set_brightness: expected int for dictionary value @ data[‘brightness’]. Got ‘13’

Also see this topic on the Home Assistant forum:
https://community.home-assistant.io/t/integer-list-in-data-template-converts-to-stings/63653

@GregoryDosh
Copy link
Contributor

I should definitely look into changing this to accept strings. I'll get into that when I'm redoing this service so it is more robust. ATM I'm dealing with some house issues so not able to make any progress on this in the near term.

@GregoryDosh
Copy link
Contributor

@Mace404 Sorry for the delay, can you check to see if it works with the updated master branch? I added some coercion and it seems to work locally with some quick testing but I don't have the templates that you do so I'm curious to see it work on your end.

@Mace404
Copy link
Author

Mace404 commented Oct 22, 2018

Unfortunately, the whole thing stopped working because of updates.
Not sure which was the breaking one, the Dreamscreen firmware or the Home Assistant one.
I rolled back a HA backup but that did not fix it.
There is no Dreamscreen discovered anymore. I saw another topic here describing the same issue.

Will grab the latest version and see what happens tho.

edit: just saw your post in the other topic, refreshing the dependencies as well.

@Mace404
Copy link
Author

Mace404 commented Oct 22, 2018

Yeah, this works, great stuff!
I can control the brightness now using a Jinja data_template!

fyi, this is the complete light entity for my Dreamscreen:

- platform: template
  lights:
    dreamscreen:
      friendly_name: Dreamscreen
      icon_template: mdi:monitor-multiple
      level_template: "{{ (state_attr('dreamscreen.dreamscreen_4k','brightness') | int * 2.55) | int }}"
      value_template: "{{ is_state('dreamscreen.dreamscreen_4k','on') }}"
      turn_on:
        service: dreamscreen.set_mode
        data:
          entity_id: dreamscreen.dreamscreen_4k
          mode: 1
      turn_off:
        service: dreamscreen.set_mode
        data:
          entity_id: dreamscreen.dreamscreen_4k
          mode: 0
      set_level:
        service: dreamscreen.set_brightness
        data_template:
          entity_id: dreamscreen.dreamscreen_4k
          brightness: "{{ (brightness / 2.55) | int }}"

@GregoryDosh
Copy link
Contributor

Awesome! Glad that did it & thanks for the example. Also thanks for the example too. That's pretty slick.

@Jossleras
Copy link

Yeah, this works, great stuff!
I can control the brightness now using a Jinja data_template!

fyi, this is the complete light entity for my Dreamscreen:

- platform: template
  lights:
    dreamscreen:
      friendly_name: Dreamscreen
      icon_template: mdi:monitor-multiple
      level_template: "{{ (state_attr('dreamscreen.dreamscreen_4k','brightness') | int * 2.55) | int }}"
      value_template: "{{ is_state('dreamscreen.dreamscreen_4k','on') }}"
      turn_on:
        service: dreamscreen.set_mode
        data:
          entity_id: dreamscreen.dreamscreen_4k
          mode: 1
      turn_off:
        service: dreamscreen.set_mode
        data:
          entity_id: dreamscreen.dreamscreen_4k
          mode: 0
      set_level:
        service: dreamscreen.set_brightness
        data_template:
          entity_id: dreamscreen.dreamscreen_4k
          brightness: "{{ (brightness / 2.55) | int }}"

Great work.

It would be nice if you could share your complete entity also for controlling the Dream Screen. I´m completely new in coding !

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

No branches or pull requests

3 participants