J3n50m4t / Home-Assistant-DreamScreen-Service

Home Assistant Service for sending commands to a Wifi enabled DreamScreen
MIT License
31 stars 15 forks source link

data_template and integer #7

Closed Mace404 closed 5 years ago

Mace404 commented 6 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

Jossleras commented 5 years ago

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 !