Need helps in some templates

I have this part of the code

                        - service: mqtt.publish
                          data:
                            qos: '2'
                            topic: cmnd/{{machine_4}}/PH_SERIAL
                            payload_template: >
                              {% set setpoint = states(set_modulado_ac04)|int %}
                              {% set liga = "ON" %} {% set modo = "COOL" %}
                              "STATUS":"{{liga}}","MODE":"{{modo}}","SETPOINT":{{setpoint}}

The part of “set_modulado_ac04” its a number variable, it seems that the number it’s been readed, but apears this error

“Error rendering data template: AttributeError: ‘dict’ object has no attribute ‘lower’”

That is not an entity id, it has no domain (domain.object_id) and it is not quoted. It should be something like this

{% set setpoint = states('sensor.set_modulado_ac04')|int(0) %}

Or this

{% set setpoint = states('input_number.set_modulado_ac04')|int(0) %}

Depending on what type of entity it is.

As Tom said, the states() function takes an entity id as an argument. If set_modulado_ac04 is a variable defined elsewhere in the automation that already returns a number or numeric string, you shouldn’t be using the states() function on it.

- service: mqtt.publish
  data:
    qos: '2'
    topic: cmnd/{{machine_4}}/PH_SERIAL
    payload_template: >
      {% set setpoint = set_modulado_ac04 | int(0) %}
      {% set liga = "ON" %} {% set modo = "COOL" %}
      "STATUS":"{{liga}}","MODE":"{{modo}}","SETPOINT":{{setpoint}}

I made this change, but it does not worked

Where are you defining the value of set_modulado_ac04?

I’m using input_number and saving in some variables like this:

variables:
  set_modulado_ue01: !input set_modulado_ue01

action:
          - service: mqtt.publish
            data:
              qos: "2"
              topic: cmnd/{{machine_1}}/irhvac
              payload_template: >
                {% set setpoint = states(set_modulado_ue01)|int %}
                {% set liga = "ON" %}
                {% set modo = "COOL" %}
                {"Vendor":"{{vendor_1}}","Power":"{{liga}}","Mode":"{{modo}}","FanSpeed":3,"Temp":{{setpoint}}}

So this is a blueprint. Moved to the correct category. Please provide the full configuration in future so we know what you are actually doing.

1 Like

The full code has more than 5000 lines, but I can show you the resume:

blueprint:
  name: Salon control with up to 1 splits machines v1
  description: Turn on the machines using Google calendar
  domain: automation

# inputs
    machine_1:
      name: Machine 1
      description: Write the MAC of Machine 1, that will recieve the command
      default: ""
    vendor_1:
      name: Protocol
      description: Write the protocolo of the machine(Ex: COOLIX | TCL112AC)
      default: ""
    machine_1_auto:
      name: Machine 1 is auto?
      description: Insert the switch of machine 1
      default: {}
      selector:
        entity:
          domain: input_boolean
    comando_enviado01:
      name: Decision entity generated machine 1
      description: It will show the decision taken by the automation for machine 1
      default: {}
      selector:
        entity:
          domain: input_text
    setpoint_enviado01:
      name: Machine 1 generated setpoint decision entity
      description: It will show which was the setpoint sent by the automation to machine 1
      default: {}
      selector:
        entity:
          domain: input_text
    set_modulado_ue01:
      name: Modulated setpoint for machine 1
      description: This setpoint modulates according to the sensor graph, to leave the environment with the established goal.
      default: {}
      selector:
        entity:
          domain: input_number
    setpoint_modular_ue01_auto:
      name: Modular setpoint automation for machine 1
      description: Place modular setpoint automation control switch for machine 1
      default: {}
      selector:
        entity:
          domain: automation

# automation

mode: single
trigger:
- platform: time_pattern
  minutes: /10
  alias: Each 10 minutes
variables:
  machine_1: !input machine_1
  vendor_1: !input vendor_1
  set_modulado_ue01: !input set_modulado_ue01
action:
    - parallel:
      - if:
        - condition: state
          entity_id: !input machine_1_auto
          state: "on"
        then:
        - if:
          - condition: state
            entity_id: !input setpoint_modular_ue01_auto
            state: "on"
          then:
          - service: mqtt.publish
            data:
              qos: "2"
              topic: cmnd/{{machine_1}}/irhvac
              payload_template: >
                {% set setpoint = states(set_modulado_ue01) |int %}
                {% set liga = "ON" %}
                {% set modo = "COOL" %}
                {"Vendor":"{{vendor_1}}","Power":"{{liga}}","Mode":"{{modo}}","FanSpeed":3,"Temp":{{setpoint}}}
          - service: input_text.set_value
            data:
              value: "ON"
            target:
              entity_id: !input comando_enviado01
          - service: input_text.set_value
            data_template:
              value: >
                {% set setpoint = states(set_modulado_ue01)|int %}
                {{setpoint}}°C
            target:
              entity_id: !input setpoint_enviado01
          else:
            - service: mqtt.publish
              data:
                qos: "2"
                topic: cmnd/{{machine_1}}/irhvac
                payload_template: >
                  {% set setpoint = states(meta) |int %}  {% set liga = "ON" %}  {% set modo = "COOL" %}
                  {"Vendor":"{{vendor_1}}","Power":"{{liga}}","Mode":"{{modo}}","FanSpeed":3,"Temp":{{setpoint}}}
            - service: input_text.set_value
              data:
                value: "ON"
              target:
                entity_id: !input comando_enviado01
            - service: input_text.set_value
              data_template:
                value: >
                  {% set setpoint = states(meta) |int %}
                  {{setpoint}}°C
              target:
                entity_id: !input setpoint_enviado01