SirGoodenough / HA_Blueprints

🧯 My Collection of Automation and Script Blueprints for Home Assistant 🧯
Other
132 stars 22 forks source link

Helper not capturing last cube side #8

Closed phairplay closed 1 year ago

phairplay commented 1 year ago

Describe the bug Helper not capturing the Last side. it's seem to skip passed it, yet I noticed the automation runs twice within a few millseconds. I'm not sure if this is normal.

To Reproduce Steps to reproduce the behavior:

  1. Go to '....'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior Helper created from the blueprint should be capturing the last side the cube was on, as per the blueprint settings

Screenshots https://imgur.com/a/9vXopOd this is taken from MQTT explore https://imgur.com/9KPJXod taken of the automation trace showing it skipping the last side element https://imgur.com/a/gqrpKwH the blank helper

What version of the blueprint has the issue? 2023.3.0

What was the version of Home Assistant Core? core-2023.3.3

What type of installation are you running? Home Assistant OS

YAML snippets INCLUDING the Script or Automation that you built to call the blueprint

- id: '1679165451196'
  alias: test
  description: ''
  use_blueprint:
    path: SirGoodenough/Zigbee2MQTT-Aqara-Magic-Cube-T1-Pro-CTP-R01-Xiaomi-Lumi.yaml
    input:
      topic: zigbee2mqtt/Cube_Desk
      action_doubletap_face_1:
      - service: light.toggle
        entity_id: light.desk_lamp
      action_rotate_cw_face_1:
      - service: light.turn_on
        entity_id: light.desk_lamp
        data_template:
          brightness: '{{states.light.desk_lamp.attributes.brightness + 30}}'
      action_rotate_ccw_face_1:
      - service: light.turn_on
        entity_id: light.desk_lamp
        data_template:
          brightness: '{{states.light.desk_lamp.attributes.brightness - 30}}'
      action_doubletap_face_2:
      - service: script.turn_on
        entity_id: script.lg_playroom_pc_on
      action_flipped90_face_3:
      - service: light.turn_on
        entity_id: light.games_room
      action_doubletap_face_3:
      - service: light.turn_on
        entity_id: light.games_room
        data:
            brightness: 76
      action_rotate_cw_face_3:
      - service: light.turn_on
        entity_id: light.games_room
        data_template:
          brightness: '{{states.light.games_room.attributes.brightness + 30}}'
      action_rotate_ccw_face_3:
      - service: light.turn_on
        entity_id: light.games_room
        data_template:
          brightness: '{{states.light.games_room.attributes.brightness - 30}}'
      action_flipped90_face_5:
      - service: media_player.turn_on
        data: {}
        target:
          entity_id: media_player.alexander_tv
      action_doubletap_face_5:
      - service: media_player.select_source
        entity_id: media_player.alexander_tv
        data:
          source: YouTube

Additional context Add any other context about the problem here.

SirGoodenough commented 1 year ago

I have mentioned that the data created by this is not something I control...

https://imgur.com/a/9vXopOd

That is not the last side sensor I use or recommend using... https://github.com/SirGoodenough/HA_Blueprints/blob/master/Automations/Zigbee2MQTT-Aqara-Magic-Cube-T1-Pro-CTP-R01-Xiaomi-Lumi.md#-how-does-this-darn-cube-work

I suggest setting up this sensor and determining if the cube is working or not. The data showing here is the data that the BP is using.

In addition the last side variable that I create is the one to monitor if you are doing automatons, as the one that the cube integrator provides only shows for some actions and is over-ridden quickly after it is displayed.

Similar to this, but with your cube name... number.yertle_last_side

SirGoodenough commented 1 year ago

Expected behavior Helper created from the blueprint should be capturing the last side the cube was on, as per the blueprint settings

Have you been able to get me more data that includes the BP Helper entity, as opposed to the Cube generated entity?

phairplay commented 1 year ago

So sorry I've been away with work for the past few days. I really appreciate the help. I'll look at this and get back to you

phairplay commented 1 year ago

Hi I get the following after setting up your sensor template

Cube_Desk - flip90 - 6 frm 0 it always says frm 0

SirGoodenough commented 1 year ago

Guess I need more data. It is working on mine. So if you can please find a trace that was successful, not a null trigger, and with the tip circle selected, please grab all the 'changed variables' data in that tab. and drop it here. Screenshot_20230323_124835

phairplay commented 1 year ago

1

this:
  entity_id: automation.desk_cube
  state: 'on'
  attributes:
    last_triggered: '2023-03-24T14:56:48.061769+00:00'
    mode: single
    current: 0
    id: '1679165451197'
    friendly_name: Desk Cube
  last_changed: '2023-03-24T14:39:14.838988+00:00'
  last_updated: '2023-03-24T14:56:49.112948+00:00'
  context:
    id: 01GWA1YJXWNFWJJR1B6RHFG77R
    parent_id: null
    user_id: null
trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: mqtt
  topic: zigbee2mqtt/Cube_Desk
  payload: >-
    {"action":"flip90","action_angle":null,**"action_from_side":1,**"battery":100,"current":0,"last_seen":"2023-03-24T14:57:00+00:00","linkquality":69,"operation_mode":"action_mode","power":0,"power_outage_count":15,"side":4,"update":{"installed_version":-1,"latest_version":-1,"state":null},"update_available":null,"voltage":3081}
  qos: 0
  description: mqtt topic zigbee2mqtt/Cube_Desk
  payload_json:
    action: flip90
    action_angle: null
    action_from_side: 1
    battery: 100
    current: 0
    last_seen: '2023-03-24T14:57:00+00:00'
    linkquality: 69
    operation_mode: action_mode
    power: 0
    power_outage_count: 15
    side: 4
    update:
      installed_version: -1
      latest_version: -1
      state: null
    update_available: null
    voltage: 3081

flipping the cube from side 1 to side 4 I can see it captures the last side it was on.

I then also notice it runs again

2

this:
  entity_id: automation.desk_cube
  state: 'on'
  attributes:
    last_triggered: '2023-03-24T14:57:00.290389+00:00'
    mode: single
    current: 1
    id: '1679165451197'
    friendly_name: Desk Cube
  last_changed: '2023-03-24T14:39:14.838988+00:00'
  last_updated: '2023-03-24T14:57:00.290532+00:00'
  context:
    id: 01GWA1YYW16D9X46FRNEJ98JZW
    parent_id: null
    user_id: null
trigger:
  id: '0'
  idx: '0'
  alias: null
  platform: mqtt
  topic: zigbee2mqtt/Cube_Desk
  payload: >-
    {"action":"","action_angle":null,**"action_from_side":null,**"battery":100,"current":0,"last_seen":"2023-03-24T14:57:00+00:00","linkquality":69,"operation_mode":"action_mode","power":0,"power_outage_count":15,"side":4,"update":{"installed_version":-1,"latest_version":-1,"state":null},"update_available":null,"voltage":3081}
  qos: 0
  description: mqtt topic zigbee2mqtt/Cube_Desk
  payload_json:
    action: ''
    action_angle: null
    action_from_side: null
    battery: 100
    current: 0
    last_seen: '2023-03-24T14:57:00+00:00'
    linkquality: 69
    operation_mode: action_mode
    power: 0
    power_outage_count: 15
    side: 4
    update:
      installed_version: -1
      latest_version: -1
      state: null
    update_available: null
    voltage: 3081

wiping out the action and the action from side, curious why it's capturing payloads twice.

phairplay commented 1 year ago

Sorry to hassle again. the template sensor you made has started working

Cube_Desk - flip90 - 3 frm 6 Yes the helper from the blueprint picks up not the last side but the current side Changed to 3 triggered by automation Desk Cube mqtt topic zigbee2mqtt/Cube_Desk

SirGoodenough commented 1 year ago

From what I can see everything is normal. If you continue to have issues, it is caused by the name you picked for the cube that has a space or an underscore it it because the way my coding ended up it likely will not match the friendly name

  topic: zigbee2mqtt/Cube_Desk

If you read the whole helper file it will help you.

https://github.com/SirGoodenough/HA_Blueprints/blob/master/Automations/Zigbee2MQTT-Aqara-Magic-Cube-T1-Pro-CTP-R01-Xiaomi-Lumi.md#never-use-spaces-in-a-topic

Regarding:

I then also notice it runs again

That's how Z2M works for most if not all actions. There is a wake-up trigger that sends null as most of the variables, then the actual trigger with data, then another null trigger to indicate that action is over, and then if it sits another trigger we don't capture to put it back to sleep.

This is why conditions are required on the triggers, to screen out things that the BP doesn't care about. If we let those trigger the rest of the BP it spams the logs with errors about null data and such.

SirGoodenough commented 1 year ago

Could not determine exact issue. No other complaints similar...

la7eralus commented 1 year ago

I know I'm late to the party ;-) I had the same issue and I just simply restarted home assistant. After that, the last state instantly worked. I think this is what OP also did (by coincidence).