home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.13k stars 29.8k forks source link

clash between rest sensor / command line #94182

Closed Appie-rappie closed 1 year ago

Appie-rappie commented 1 year ago

The problem

Starting version 2023-06, I'm unable to get two elements of my configuration.yaml working at the same time. One element is a REST interface to Ambeedata, the other is a command line interface with a 433MHz hub. Both work, just not at the same time. When I restart HA, the 433MHz hub works, but not Ambeedata. When I quick reload the configuration, it's the other way around.

Configuration below was edited to reflect the changes in command line structure, but the original configuration behaves exactly the same in version 2023.06 and works without problems in version 2023.5.4.

Below the two snippets from my configuration.yaml file.

What version of Home Assistant Core has the issue?

2023-6

What was the last working version of Home Assistant Core?

2023.5.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

REST, command line

Link to integration documentation on our website

https://www.home-assistant.io/integrations/rest/

Diagnostics information

No response

Example YAML snippet

sensor:
  - platform: rest
    name: pollen_data
    scan_interval: 3600
    resource_template: https://api.ambeedata.com/latest/pollen/by-lat-lng?lat={{ state_attr("zone.home", "latitude") }}&lng={{ state_attr("zone.home", "longitude") }}
    value_template: >-
      {{ value_json.message}}
    headers:
      content-type: application/json
      x-api-key: !secret ambee-api
    json_attributes_path: data[0]
    json_attributes:
      - Count
      - Risk
      - Species
      - updatedAt
      - time

and:

command_line:
  - switch:
      name: Lader
      command_on: >-
        curl -d '{"state":"on","lightname":"lader"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      command_off: >-
        curl -d '{"state":"off","lightname":"lader"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      command_state: >-
        curl -d '{"state":"?","lightname":"lader"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      value_template: '{{ value_json.state == "on" }}'
      unique_id: "Lader"
      scan_interval: 30
  - switch:
      name: LED strip
      command_on: >-
        curl -d '{"state":"on","lightname":"LED strip"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      command_off: >-
        curl -d '{"state":"off","lightname":"LED strip"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      command_state: >-
        curl -d '{"state":"?","lightname":"LED strip"}' -H 'Content-Type: application/json' http://192.168.2.21:5000/lights
      value_template: '{{ value_json.state == "on" }}'
      unique_id: "LED strip"
      scan_interval: 30

Anything in the logs that might be useful for us?

I get no useful log entries, just 'latitude has to be an integer' when Ambee is not working, when it is working no useful log entries at all.

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @epenet, mind taking a look at this issue as it has been labeled with an integration (rest) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `rest` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign rest` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


rest documentation rest source (message by IssueLinks)

home-assistant[bot] commented 1 year ago

Hey there @gjohansson-st, mind taking a look at this issue as it has been labeled with an integration (command_line) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `command_line` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign command_line` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


command_line documentation command_line source (message by IssueLinks)

epenet commented 1 year ago

I think there are two issues that should really be tracked separately: one is the ambeedata issue, and one is the reload issue.

Regarding ambeedata: the first thing that I recommend is to move from the platform key configuration to the integration key configuration (from sensor -> rest to rest -> sensor) See https://www.home-assistant.io/integrations/rest You should also add an availability template, to ensure that {{ state_attr("zone.home", "latitude") }} is a number before sending ambeedata requests.

Regarding reload, please look at #93538 which attempts to fix reload issues.

Appie-rappie commented 1 year ago

Sounds very plausible, all the more as I discovered that in the old situation it also only worked after a quick restart. Sorry for not noticing it sooner. Thanks! I implemented your suggestions in version 2023.5.4 and have it working, also on the first start. I suppose that's one problem solved.

I'm still hesitant to upgrade to 2023.06 as I suspect the command line sensors would still not work after a quick restart.

freeDom- commented 1 year ago

I think there are two issues that should really be tracked separately: one is the ambeedata issue, and one is the reload issue.

Regarding ambeedata: the first thing that I recommend is to move from the platform key configuration to the integration key configuration (from sensor -> rest to rest -> sensor) See https://www.home-assistant.io/integrations/rest You should also add an availability template, to ensure that {{ state_attr("zone.home", "latitude") }} is a number before sending ambeedata requests.

Regarding reload, please look at #93538 which attempts to fix reload issues.

Why is rest -> sensor configuration preferred and is this documented somewhere? In the Restful HA docu it is not mentioned that sensor -> rest could make problems, but it is advised to use it when only adding one sensor via rest interface...

epenet commented 1 year ago

rest -> sensor/binary_sensor has automatic support for multiple entities with the same resource so if you download a JSON with multiple values you can use that single resource with lots of sensors+binary sensors

sensor -> rest is being phased out on every integration (not just rest) It will be fully deprecated once switch and notify platforms are migrated.

Appie-rappie commented 1 year ago

Hi @gjohansson-ST, do you think the problem of these command-line lines not working anymore after a quick reload is solved? I'm still reverted to version 2023.5.4, as I need the integration with my 433 MHz hub that these lines represent to work.

gjohansson-ST commented 1 year ago

See here for the reload issue. I will close this issue now as it's tracked in the other one. Thanks