Lovelace manual setup and call-service woes

Hi, first time poster and quite new to Home Assistant. So hopefully I’m not breaking any site etiquette with this post (and sorry for the long post).

I’m currently converting my Hue and Smartlife devices to Home Assistant through hass.io. I’m having a issue about controlling lights in Lovelace. I want to use a floor layout and position my lights at their corresponding location and it is working Ok but I’m having issues controlling the lights that allow dimming that way. Below is the floor plan for my ground floor.

image

And Below is the curated version of the Lovelace script (only get the dimer to make things easier to read.

script:
  g_bright_mode:
    sequence:
      - service: light.turn_on
        data_template:
          entity_id: '{{ input_light }}'
          brightness: 255
          color_temp: 226
elements:
  - entity: light.lumieredimmertest
    filter: saturate(.8)
    image: /local/lightbulb_on.png
    state_filter:
      'on': brightness(120%) saturate(1.2)
      style:
        left: 62%
        top: 13%
    state_image:
      'off': /local/lightbulb_off.png
      unavailable: /local/lightbulb_unavailable.png
    style:
      left: 62%
      rotate: 90
      top: 13%
    tap_action:
      action: toggle
    hold_action:
      action: call-service
      service: script.g_bright_mode
      service_data:
        input_light: light.lumieredimmertest
    type: image

image: /local/PlanRDC.png
type: picture-elements

The tap action is working fine but the hold action is returning "Failed to call service script/g_bright_mode. Service not found.

You’ll see the script is there above the elements. I Tried to move it below as well as move it into scripts.yaml. To no avail, I can’t get it to work. If I replace “service: script.g_bright_mode” with “service:light.turn_on”, and change “input_light” for “entity_id”, I get instead “Failed to call service light/turn_on. must contain one of entity_id, area_id”.

If I move the call-service in the tap action instead of hold, it behaves the same way so I don’t think it’s related to it being in the hold section.

I already spent several hours on this, trying different things (the name of the script is actually something I found in a post in this community) and I’m stuck and can’t figure out what I’m doing wrong. Any help appreciated.

Edit: Replaced “service data” for “service_data”, copy/paste error.

missing underscore in service_data.

    hold_action:
      action: call-service
      service: script.g_bright_mode
      service data: #<-----
        input_light: light.lumieredimmertest
    hold_action:
      action: call-service
      service: script.g_bright_mode
      service_data:
        input_light: light.lumieredimmertest

Thanks for the quick reply. That’s actually what I had. It’s just with all the trials an errors I did, it ended up like that. I’ll correct the original post with an edit (if allowed here).

so with it fixed, it does not work? Is there a full error in the log?

No, it still doesn’t work. Where can I find the log files?

go to your config folder, and in there should be a file named ‘home-assistant.log’ or something like that. Use baretail or refresh the file after you use the ‘hold action’ to see what home assistant complains about.

As shown by a
find / -name “*.log”

“/config/home-assistant.log” is the only ‘.log’ on my hassio installation.

A
tail -f /config/home-assistant.log

before trying to hold the light entity shows nothing being recorded in the log file after I got the error message on the webpage

image .

As far as I know, a script needs to be in scripts.yaml. Can you move it there and then reload the scripts? Your syntax seems fine otherwise. The error points to the script not being found.

That’s one of the tries I did during those hours of trials and errors last night :frowning: It didn’t work there either. What puzzles me though is why a simple

    hold_action:
      action: call-service
      service: light.turn_on
      service_data:
        entity_id: light.lumieredimmertest

ALSO did NOT work! I got a “Failed to call service light/turn_on. must contain one of entity_id, area_id”. From the documentation, it should work. Don’t know what I’m doing wrong and it’s getting frustrating :angry:

I feel with you, it can be frustrating at times. To me, the code you posted seems fine. I can only advise you to pick 1 case you’d like help with, post the full code and be concise. And keep a good mood :upside_down_face:

what are you using to edit the yaml? Are you using spaces and tabs, just tabs, or just spaces?

Tried multiple methods. The script editor in Configuration, the one in Configurator plug-in, the built-in Lovelace manual editor and Notepadd++ (to cut and paste between both). Notepad++ might have added some tabs. I’ll check and make sure there are no tabs.

The built in editors didn’t report any issues though, but don’t know if it checks for space/tab and if it matters.

I don’t either. I do know that notepad++ by default does not change tabs to spaces. And you want to do that with yaml and python.

Just checked and every blank char is a space and not a tab.

So I went back to a very basic setup in Lovelace and scripts. This is what I have (as screenshot so you see what I see)

In Configurator:
image

image

In Overview - Raw config editor
image
(ps, swapped action and hold_action so it’s easier to test and to confirm it’s not hold_action misbehaving)

After a ‘reload’ of the scripts from Configuration-Server Controls-RELOAD SCRIPTS, I still get
image

Not sure what else I can try!

Found my mistake. I need to use

service: script.1577559145650

and not

service: script.test123

Although I read that you HAVE to use the script aliases, it appears you actually can’t. Well, in my installation I can’t…

Great to hear that you got it working. From your example, I think your script is missing the entity_id? It would need something like you had in your very first example script:
entity_id: '{{ input_light }}'
But if it’s working for you, just leave it be I guess!

Edit: I will forever remember one needs to call a GUI-generated script by its number, thanks.

Yeah, the real code is like this: (I didn’t use the script wizard so I could use real name and not meaningless numbers and used state-icon instead of image for ‘type’). One thing I did wrong with all my tests the other day is forgetting to reload the scripts. Lovelace doesn’t need to reload before being active but scripts do and I forgot about it :flushed:

Lovelace UI raw config (just for that light):

  - elements:
	  - entity: light.lumieredimmertest
		type: state-icon
		style:
		  left: 62%
		  rotate: 90
		  top: 13%
		tap_action:
		  action: toggle
		hold_action:
		  action: call-service
		  service: script.light_fullbright
		  service_data:
			input_light: light.lumieredimmertest
		double_tap_action:
		  action: call-service
		  service: script.light_halfbright
		  service_data:
			input_light: light.lumieredimmertest

Scripts.yaml:

'light_fullbright':
  sequence:
    data_template:
      brightness: 255
      entity_id: '{{ input_light }}'
    service: light.turn_on
'light_halfbright':
  sequence:
    data_template:
      brightness: 128
      entity_id: '{{ input_light }}'
    service: light.turn_on