Need help converting deprecated YAML!

Hi,

now that version 12 is here, I have to convert a mammoth script of MQTT sensors from platform mode.

Trouble is, it seems to depend on platform statistics too!

Are there any HA yaml gurus who’d be willing to look at this and give me a clue?

I’d be REALLY grateful!

I think the worst bit is that the MQTT sensor seems to get its entity_id from the Statistics statement, but it’s all very confusing. (It was inherited as part of a non-supported package)

Thanks!

etrv_bedroom:
  sensor:
    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Temperature/8163"
      name: "Bedroom Temperature"
      unit_of_measurement: "°C"
      force_update: true
      expire_after: 660

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/TargetTemperature/8163"
      name: "Bedroom Target Rcvd"
      unit_of_measurement: "°C"

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Voltage/8163"
      name: "Bedroom TRV Voltage"
      unit_of_measurement: V
      force_update: true

    - platform: mqtt
      state_topic: "/energenie/eTRV/Command/ValveState/8163"
      name: "command_valvestate_8163"

    - platform: mqtt
      state_topic: "/energenie/eTRV/Command/Temperature/8163"
      name: "command_temperature_8163"

    - platform: statistics
      name: bedroom_etrv_stats
      entity_id: sensor.bedroom_temperature
      state_characteristic: mean
      max_age:
        minutes: 25

  binary_sensor:
    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV Motor current below expectation"
      value_template: '{{ value_json["Motor current below expectation"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV Motor current always high"
      value_template: '{{ value_json["Motor current always high"] }}'
      payload_on: true
      payload_off: false


    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV Motor taking too long"
      value_template: '{{ value_json["Motor taking too long"] }}'
      payload_on: true
      payload_off: false


    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV discrepancy between air and pipe sensors"
      value_template: '{{ value_json["discrepancy between air and pipe sensors"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV air sensor out of expected range"
      value_template: '{{ value_json["air sensor out of expected range"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV pipe sensor out of expected range"
      value_template: '{{ value_json["pipe sensor out of expected range"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV Low Power Mode Enabled"
      value_template: '{{ value_json["low power mode is enabled"] }}'
      payload_on: true
      payload_off: false


    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV no target temperature has been set by host"
      value_template: '{{ value_json["no target temperature has been set by host"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV valve may be sticking"
      value_template: '{{ value_json["valve may be sticking"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV valve exercise was successful"
      value_template: '{{ value_json["valve exercise was successful"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV valve exercise was unsuccessful"
      value_template: '{{ value_json["valve exercise was unsuccessful"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV driver micro has suffered a watchdog reset and needs data refresh"
      value_template: '{{ value_json["driver micro has suffered a watchdog reset and needs data refresh"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV driver micro has suffered a noise reset and needs data refresh"
      value_template: '{{ value_json["driver micro has suffered a noise reset and needs data refresh"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV battery voltage has fallen below 2.2V and valve has been opened"
      value_template: '{{ value_json["battery voltage has fallen below 2p2V and valve has been opened"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV request for heat messaging is enabled"
      value_template: '{{ value_json["request for heat messaging is enabled"] }}'
      payload_on: true
      payload_off: false

    - platform: mqtt
      state_topic: "/energenie/eTRV/Report/Diagnostics/8163"
      name: "Bedroom TRV request for heat"
      value_template: '{{ value_json["request for heat"] }}'
      payload_on: true
      payload_off: false

  switch:
    - platform: mqtt
      name: "Bedroom TRV Low Power Mode"
      command_topic: "/energenie/eTRV/Command/PowerMode/8163"
      state_topic: "/energenie/eTRV/Command/PowerMode/8163"
      payload_on: 1
      payload_off: 0
      retain: true

  input_number:
    bedroom_temp:
      name: Bedroom Temperature Target
      min: 4
      max: 30
      step: 1
      unit_of_measurement: "°C"
      mode: slider
      initial: 18
      icon: mdi:thermometer-lines

  input_select:
    bedroom_trv_state:
      name: Bedroom TRV Valve State
      options:
        - Closed
        - Normal
        - Open

  script:
    send_report_voltage_bedroom:
      sequence:
        - service: script.send_trv_command
          data:
            id: '8163'
            command: 'Voltage'

    send_report_diagnostics_bedroom:
      sequence:
        - service: script.send_trv_command
          data:
            id: '8163'
            command: 'Diagnostics'

    send_exercise_bedroom:
      sequence:
        - service: script.send_trv_command
          data:
            id: '8163'
            command: 'Exercise'

    send_identity_bedroom:
      sequence:
        # This is written using the Script Syntax
        - service: script.send_trv_command
          data:
            id: '8163'
            command: 'Identify'

  group:
    bedroom_trv:
      entities:
        - sensor.bedroom_temperature
        - input_number.bedroom_temp
        - sensor.bedroom_target_rcvd
        - input_select.bedroom_trv_state
        - switch.bedroom_trv_low_power_mode
        - script.send_report_diagnostics_bedroom
        - script.send_exercise_bedroom
        - script.send_identity_bedroom
        - script.send_report_voltage_bedroom
        - sensor.bedroom_trv_voltage

    bedroom_diagnostics:
      entities:
        - binary_sensor.bedroom_trv_motor_current_below_expectation
        - binary_sensor.bedroom_trv_motor_current_always_high
        - binary_sensor.bedroom_trv_motor_taking_too_long
        - binary_sensor.bedroom_trv_discrepancy_between_air_and_pipe_sensors
        - binary_sensor.bedroom_trv_air_sensor_out_of_expected_range
        - binary_sensor.bedroom_trv_pipe_sensor_out_of_expected_range
        - binary_sensor.bedroom_trv_low_power_mode_enabled
        - binary_sensor.bedroom_trv_no_target_temperature_has_been_set_by_host
        - binary_sensor.bedroom_trv_valve_may_be_sticking
        - binary_sensor.bedroom_trv_valve_exercise_was_successful
        - binary_sensor.bedroom_trv_valve_exercise_was_unsuccessful
        - binary_sensor.bedroom_trv_driver_micro_has_suffered_a_watchdog_reset_and_needs_data_refresh
        - binary_sensor.bedroom_trv_driver_micro_has_suffered_a_noise_reset_and_needs_data_refresh
        - binary_sensor.bedroom_trv_battery_voltage_has_fallen_below_2_2v_and_valve_has_been_opened
        - binary_sensor.bedroom_trv_request_for_heat_messaging_is_enabled
        - binary_sensor.bedroom_trv_request_for_heat

They change the rules

MQTT is its own thing now not part of a platform

Yes, I get that.
However, the file that I have inherited has several different platforms woven together and I don’t know how to unpick them.

You move all the mqtt items to your configuration.yaml file and put them under mqtt: and follow the new format.

1 Like

Sorry, I’m not making myself clear.
Specific problem: After the sensor: group there is a

platform: statistics

declaration. note that it is tied into the MQTT sensor, and declares its entity_id .
How do I deal with that?

Sadly, I didn’t get into HA early enough to really get to grips with the old format in time to know enough how to translate it into the new format.

I don’t even know if the line

state_characteristic: mean

is correct. It wasn’t in the original script, but was another of those deprecated changes required. I have a feeling - though I don’t know - that the sole purpose of the platform:statistics is to put the text temperature into the entity_id.

Argh!

That is a completely different sensor platform. You don’t do anything to it. Leave it as it is. You only need to change the mqtt platform entities. As long as your new mqtt sensors have the same entity ids the statistics sensors will keep working.

Thanks for that, but it doesn’t work for me.

I have reduced my packages.yaml file to a bare minimum, which fails with:

Invalid config for [mqtt]: [platform] is an invalid option for [mqtt]. Check: mqtt->mqtt->sensor->5->platform.

It doesn’t seem to like the platform: statistics, and I don’t know how to fix it. Please have a quick look below - the failing statement is on the bottom.

Thanks!
(PS I have no idea why it isn’t formatting correctly here!)

etrv_bedroom:
  mqtt:
    sensor:
      - state_topic: "/energenie/eTRV/Report/Temperature/8163"
        name: "Bedroom Temperature"
        unit_of_measurement: "°C"
        force_update: true
        expire_after: 660

      - state_topic: "/energenie/eTRV/Report/TargetTemperature/8163"
        name: "Bedroom Target Rcvd"
        unit_of_measurement: "°C"

      - state_topic: "/energenie/eTRV/Report/Voltage/8163"
        name: "Bedroom TRV Voltage"
        unit_of_measurement: V
        force_update: true

      - state_topic: "/energenie/eTRV/Command/ValveState/8163"
        name: "command_valvestate_8163"

      - state_topic: "/energenie/eTRV/Command/Temperature/8163"
        name: "command_temperature_8163"

      - platform: statistics
        name: bedroom_etrv_stats
        entity_id: sensor.bedroom_temperature
        state_characteristic: mean
        max_age:
        minutes: 25

As @tom_l said, the statistics sensor is not an MQTT sensor. Pull that out from the mqtt: section and put it back under sensor:.

So (and no idea what etrv_bedroom: is all about: assume this is a packaged setup?):

etrv_bedroom:
  mqtt:
    sensor:
      - [all the other MQTT sensors as posted]
      - state_topic: "/energenie/eTRV/Command/Temperature/8163"
        name: "command_temperature_8163"
  sensor:
    - platform: statistics
      name: bedroom_etrv_stats
      entity_id: sensor.bedroom_temperature
      state_characteristic: mean
      max_age:
      minutes: 25
1 Like

At last I think I understand.

Thanks all for your help!

B.

Ignore my last if you saw it before deletion… stupid indentation error!

Please make a new post with an actual solution if you intend to use the solution checkbox. Do not mark a post without a solution as the solution. FYI “Thanks for your help” is not a solution. So if you don’t intend to post your actual solution, don’t use the checkbox. Thank you.

Apologies! I checked the wrong box - how stupid of me!

B.