#Moving a work Command_line sensor in another config but it doesnt work

1 messages · Page 1 of 1 (latest)

rustic turret
#

Hey i need some help, i have a working commandline sensor in a command_line.yaml file thats included like this command_line: !include command_line.yaml in the configuration.yaml.
Now i moved it from the config directory into the packages folder, renamed it to speedtest.yaml and include it like this homeassistant: packages: !include_dir_named packages
But its not working now even though i adapted the config to the new syntax.
I attached both .yaml files, i am assuming it might be connected to the path, but it should not have changed since all since the .json files the sensors are calling stayed in the same place. Hope this is an easy issues for some of you experts

void valve
#

neither of those starts with command_line:

rustic turret
ruby salmon
#

It makes sense that the file you include doesn't start with command_line: as you already have that in configuration.yaml

#

But in packages you need to add the integration

void valve
#

you need to follow the complete definition in your new package

rustic turret
# ruby salmon But in packages you need to add the integration

but am i not doing that with the platform: command_line key? i am doing something similar with template sensors and this works as follows:

  # Template Sensors
  - platform: template
    sensors:
      speedtest_cron_download:
        unique_id: "speedtest_cron_download"
        friendly_name: Download
        value_template: '{{ states.sensor.speedtest_cron.attributes.download.bandwidth | multiply(0.000008) | round(2) }}'
        unit_of_measurement: 'Mbit/s'
        availability_template: '{{ states("sensor.speedtest_cron") != "unavailable" and states.sensor.speedtest_cron.attributes.download.bandwidth is defined }}'```
void valve
#

you can't use platform: command_line anymore

#

see the docs

#

that's been gone for a long time

#

and it wasn't what you were using before

#

you can use whatever you had in configuration.yaml in a package directly, as-is. You don't need to go and modify anything

#

you're doing extra work and breaking things

rustic turret
#

ahh okay i understand now, i thought the syntax with the platform key is for all keys just depending on how they are called in the config

void valve
#

no, you need to follow the docs for each integration

#

everything is slowly moving away from the platform: xxx syntax

rustic turret
#

Alright i understand now, thank you i have it working now with the following

  - sensor:
      name: speedtest_cron
      unique_id: speedtest_cron
      command: "cat /config/speedtest_cmd/speedtest-result-crontab.json"
      scan_interval: 120
      command_timeout: 5
      json_attributes:
        - isp
        - download
        - upload
        - interface
        - server
        - timestamp
      value_template: "{{ value_json.download['bandwidth'] }} / {{ value_json.upload['bandwidth'] }}"
  
  - sensor:
      name: ping_test_cron
      unique_id: "ping_test_cron"
      command: "cat /config/speedtest_cmd/ping-result-crontab.json"
      scan_interval: 120
      command_timeout: 5
      json_attributes:
        - report
      value_template: "{{ value_json.report.mtr['dst'] }}"```
void valve
#

you can also just include the file exactly like before if you want

rustic turret
#

which one would be the " better" or correcter way to do it?

void valve
#

entirely personal preference

#

if the reason that led you to include the file before is negated by moving to a package, keep what you have above

rustic turret
#

alright then ill go with the one above
reason for moving away from what i had before was, that my sensors and things were all scattered and i want to put them into packages so i have everything related to "speedtest" for example in the same file, before or when i setup HA for the first time i thought seperating by type would be best but now that i hav alot more stuff i find myself searching for things alot, so id like to group them better

#

but if everything is moving away from the platform syntax, ill definetly move away from it, i have that probably everywhere 😄 gues sill do that in the same process now