Another breaking change in the Template integration v0.117.x

Does anyone know how to change this template for the upcoming changes in 0.117.x?

alias: Scan for arrive and depart
initial_state: "on"
trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: binary_sensor.entity_id_for_bt_scanning
    to: "on"
condition:
  condition: and
  conditions:
    - condition: template
      value_template: "{{as_timestamp(as_local(states.sensor.time.last_changed)) - as_timestamp(state_attr('automation.scan_for_arrive_and_depart', 'last_triggered')) | float > 45 }}"
action:
  - service_template: >
      {% if is_state('script.mqtt_arrive_depart_script', 'on') %}
         script.turn_off
      {% else %}
         script.turn_on
      {% endif %}
    data_template:
      entity_id: >
        {% if is_state('script.mqtt_arrive_depart_script', 'on') %}
           script.mqtt_arrive_depart_script
        {% else %}
           script.dummy
        {% endif %}
  - wait_template: "{{ is_state('script.dummy', 'off') }}"
  - service: script.mqtt_arrive_depart_script
    data_template:
      #  {"identity":"{{trigger.entity_id.split(".")[1]}} {{as_local(states.sensor.time.last_changed).strftime("%H:%M")}}"}
      identity: >
        {% if trigger.platform == 'state' %}  
           {"identity":"{{states("sensor.entity_id_for_bt_scanning")}} {{as_local(states.sensor.time.last_changed).strftime("%H:%M")}}"}}
        {% else %}
           {"identity":"HA-start {{as_local(states.sensor.time.last_changed).strftime("%H:%M")}}"}
        {% endif %}

This is the error

Logger: homeassistant.components.automation.scan_for_arrive_and_depart
Source: components/mqtt/__init__.py:782
Integration: Automatisering (documentation, issues)
First occurred: 18:51:18 (2 occurrences)
Last logged: 18:51:18

Scan for arrive and depart: Error executing script. Unexpected error for call_service at pos 3: payload must be a string, bytearray, int, float or None.
While executing automation automation.scan_for_arrive_and_depart
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in _async_call_service_step
    await self._async_run_long_action(service_task)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 422, in _async_run_long_action
    long_task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 215, in service_handler
    await script_entity.async_turn_on(
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 320, in async_turn_on
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1010, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 245, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in _async_call_service_step
    await self._async_run_long_action(service_task)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 422, in _async_run_long_action
    long_task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 215, in service_handler
    await script_entity.async_turn_on(
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 320, in async_turn_on
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1010, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 245, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 581, in async_publish_service
    await hass.data[DATA_MQTT].async_publish(msg_topic, payload, qos, retain)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 782, in async_publish
    msg_info = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1259, in publish
    raise TypeError(
TypeError: payload must be a string, bytearray, int, float or None.

Or this one?

id: "1596xxx5"
alias: Unavailable entities sensor update
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: "{{ states('sensor.uptime_in_uren')|float > 0.05|float }}"
action:
  - variables:
      entity_ids: |-
        {{ states   
          | selectattr('state','in',['unavailable','unknown','none'])
          | rejectattr('entity_id','in',state_attr('group.ignored_entities', 'entity_id'))
          | rejectattr('domain','eq','group')
          | map(attribute='entity_id')
          | list
          | join(',')
        }}
      names: |-
        {% set ns = namespace(names=[]) %}

        {% for dev in entity_ids.split(',') %}
          {% set ns.names = ns.names + [state_attr(dev, 'friendly_name')] %}
        {% endfor %}

        {{ ns.names | to_json }}
      num: '{{ entity_ids.split(",") | length - 1 }}'
  - service: mqtt.publish
    data:
      topic: homeassistant/unavailable_entities
      payload: |-
        {
          "num": {{ num }},
          "names": {{ names }},
          "entity_ids": {{ entity_ids.split(',') | to_json }}
        }

error

Logger: homeassistant.components.automation.unavailable_entities_sensor_update
Source: components/mqtt/__init__.py:782
Integration: Automatisering (documentation, issues)
First occurred: 18:55:00 (4 occurrences)
Last logged: 19:00:00

Unavailable entities sensor update: Error executing script. Unexpected error for call_service at pos 2: payload must be a string, bytearray, int, float or None.
While executing automation automation.unavailable_entities_sensor_update
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 253, in _async_step
    await getattr(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 460, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1448, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1483, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 581, in async_publish_service
    await hass.data[DATA_MQTT].async_publish(msg_topic, payload, qos, retain)
  File "/usr/src/homeassistant/homeassistant/components/mqtt/__init__.py", line 782, in async_publish
    msg_info = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1259, in publish
    raise TypeError(
TypeError: payload must be a string, bytearray, int, float or None.

@petro
You can close this one…

Okay, unless you want me to close the other. Doesn’t matter to me.

Ok close the other then…

1 Like

Show the script that fails as well please. Your issue is related to the change that Jinja outputs python types instead of strings, so your automation passes a dict to the script not a steing that looks like a dict.

1 Like