Command Line YAML configuration has moved error

those aren’t command_line sensors.

Only
- platform: command_line
can be rewriten to new format.

If you have any other platform i.e. wake_on_lan, time, rest etc. you simply can not do that

Template has it’s own format so can be move to a separate file Template - Home Assistant

@bluestar888 in your case if you want to rewrite it to new format it should be something like below (not tested):

In the configuration.yaml file add:
template: !include template.yaml

Now you need to create template.yaml file and put inside below:

- sensor:
  - name: "Sunrise"
    state: '{{ as_timestamp(state_attr("sun.sun", "next_rising")) | timestamp_custom("%H:%M") }}'
    unit_of_measurement: ""

- sensor:
  - name: "Sunset"
    state: '{{ as_timestamp(state_attr("sun.sun", "next_setting")) | timestamp_custom("%H:%M") }}'
    unit_of_measurement: ""
1 Like

Thank you ,I will test and see. So basically since there is no command to do actively do something I leave it as is just change the template format.

command_line is the integration. What you’re showing here is template sensors, which is the template integration. The only change occurred with the command_line integration.

I’ve noticed that since this change, my command line switches disappear randomly. The only way to get them back is a reboot.

- switch:
    name: projector
    command_on: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] 'python pyjector_controller benq /dev/ttyUSB0 power on'
    command_off: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] 'python pyjector_controller benq /dev/ttyUSB0 power off'
- switch:
    name: restartvpn
    command_on: ssh -i /config/.ssh/id_rsa -o 'StrictHostKeyChecking=no' [email protected] './restartVPN'

Ok, so I am trying to convert my command line sensors and switches over and failing miserably. I think my format is ok, but I think my directory structure is causing a problem. I should be able to do the following, but is seems to not work.

/config/sensor/
command_line_sensor.yaml
xxx.yaml
yyy.yaml

/config/switch/
command_line_switch.yaml
xxx.yaml
yyy.yaml

The directories are inplace and the includes have been working for ages, just moved the command line entries to a new yaml file in the existing structure.

Here is my command_line_sensor.yaml contents:

command_line:
  - sensor:
      name: dr_temp
      command: 'ssh -i /config/.ssh/id_rsa -F /config/.ssh/config [email protected] sudo ./scripts/lm75a.sh -f'
      value_template: '{{ (value | float-1) | round(1) }}'
      unit_of_measurement: '°F'
      scan_interval: 60

  - sensor:
      name: router_webserver_state
      command: response=$(curl -LIk -m 3 http://192.168.1.1 -o /dev/null -w "%{remote_ip}\n" -s); test "$response" = "192.168.1.1" && echo "on" || echo "off" 
      scan_interval: 60
      value_template: '{{ value }}'
  
  - sensor:
      name: CPU Temperature
      command: "cat /sys/class/thermal/thermal_zone2/temp"
      unit_of_measurement: '°F'
      value_template: "{{ value | float | multiply(0.001) | multiply(1.8) + 32 | round(1)}}"

Ideas?

I think I read somewhere that you can only have one “command_line:” entry. Either in the base config file or referencing a separate include file. But, my YAML skills leave a lot t to be desired. I would put all of the command_line entries in one file and see if that works before splitting them out. What error are you getting?

Command line goes in configuration.yaml, not in a sensor section or switch section.

I was able to use an include and include a file in a sub-directory under /config/command_lines/command_lines.yaml

I have a binary sensor somewhere that is a command line sensor that I can’t find, but all of my other switches and sensors combined in the above file works fine.

No go . I kept my sensor.yaml and pasted your code and got a double error as per screenshot.
If I keep my original header then I get a command line error when trying to reload command line entities.

platform: template
sensors:
sunrise:

image

Home Assistant Core

Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘sunrise’]. Got [{‘name’: ‘Sunrise’, ‘state’: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_rising”)) | timestamp_custom("%H:%M") }}’, ‘unit_of_measurement’: ‘’}] expected dictionary for dictionary value @ data[‘sensors’][‘sunset’]. Got [{‘name’: ‘Sunset’, ‘state’: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_setting”)) | timestamp_custom("%H:%M") }}’, ‘unit_of_measurement’: ‘’}]. (See /config/configuration.yaml, line 66). Please check the docs at Template - Home Assistant

2:25:53 PM – (ERROR) config.py - message first occurred at 2:06:29 PM and shows up 6 times

====

Home Assistant Core

Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/sensor.yaml, line 1). Please check the docs at Sensor - Home Assistant

2:29:55 PM – (ERROR) config.py - message first occurred at 2:29:55 PM and shows up 2 times

[139668355555664] while parsing a block mapping in “/config/sensor.yaml”, line 19, column 5 expected , but found ‘’ in “/config/sensor.yaml”, line 20, column 30

Can you please post your configuration.yaml, template.yaml and sensor.yaml files?
If you didn’t comment out the Sunset and Sunrise sensors from the sensor.yaml file, it may cause some issue but need to look at the code the say something more.

sensor.yaml
This currently does not throw any errors ,just will not resolve the sunrise ,sunset sensors ,the other ones work. If I paste the code on the developer panel it resolves sunset & sunrise.

platform: template
sensors:
sunrise:
friendly_name: “Sunrise”
unit_of_measurement: “”
value_template: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_rising”)) | timestamp_custom("%H:%M") }}’

sunset:
friendly_name: “Sunset”
unit_of_measurement: “”
value_template: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_setting”)) | timestamp_custom("%H:%M") }}’

period_of_day:
friendly_name: ‘Period of day’
value_template: >-
{% if (as_timestamp(states.sun.sun.attributes.next_dusk)) - (as_timestamp(states.sun.sun.attributes.next_setting)) < 0 %}
Dusk
{% elif (as_timestamp(states.sun.sun.attributes.next_rising)) - (as_timestamp(states.sun.sun.attributes.next_dawn)) < 0 %}
Dawn
{% elif (states.sun.sun.attributes.elevation) < 0 %}
Night
{% else %}
Daytime
{% endif %}
icon_template: >-
{% if is_state(‘sun.sun’, ‘above_horizon’) %}
mdi:weather-sunny
{% else %}
mdi:weather-night
{% endif %}

sunstate:
friendly_name: “Sun State”
value_template: >
{% if is_state(‘sun.sun’, ‘above_horizon’) %}
Up
{% else %}
Down
{% endif %}


configuration.yaml

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Deprecated but still recommended by various documens out there

sun:
latitude: 49.22924
longitude: -123.0048
elevation: 14

The themes

frontend:
themes: !include_dir_merge_named themes

#Browser Mod
browser_mod:
prefix: ‘browser_mod_’

trying to reduce database size

recorder:
auto_purge: true
purge_keep_days: 60
exclude:
entity_globs:

  • sensor.*_uptime

Enable Home Assistant API

api:

Enable Virtual Platform

virtual:

logger:

The next line sets the default logging level, for all python modules.

It seems “recommended” to set it to avoid too much logging.

default: warning
logs:
custom_components.zha_toolkit: debug
homeassistant.components.zha: debug
zigpy: debug
#homeassistant.components.govee: debug
#custom_components.govee: debug
#govee_api_laggat: debug
#aiounifi: debug
#homeassistant.components.unifi: debug
#homeassistant.components.device_tracker.unifi: debug
#homeassistant.components.switch.unifi: debug

Allowlist_external_dirs:

- /media

media_source:
media_dirs:
media: /media
local: /media

Text to speech

tts:

  • platform: google_translate

Links to external configuration files

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor misc: !include sensor.yaml
sensor sysmon: !include sysmon.yaml
camera: !include cameras.yaml
envisalink: !include envisalink.yaml
cover: !include covers.yaml
#virtualswitch: !include vswitch.yaml
#datetime: !include datetime.yaml

input_datetime:
both_date_and_time:
name: Input with both date and time
has_date: true
has_time: true
only_date:
name: Input with only date
has_date: true
has_time: false
only_time:
name: Input with only time
has_date: false
has_time: true

Example configuration.yaml entry

#command_line:

- sensor:

command: SENSOR_COMMAND

sensor:

  • platform: time_date
    display_options:
    • ‘time’
    • ‘date’
    • ‘date_time’
    • ‘date_time_utc’
    • ‘date_time_iso’
    • ‘time_date’
    • ‘time_utc’
    • ‘beat’

SOnoff LAN - Unflashed SONOFF devices -used by ALex’s integration

sonoff:
username: !secret sonoff_username
password: !secret sonoff_password
sensors: [power, current, voltage]
mode: local
reload: always
force_update: True

The Alarm Integration

binary_sensor:

  • platform: envisalink

InfluxDB

influxdb:
host: 192.168.30.203
port: 8086
database: homeassistant
username: haaslocalInfluxDB
password: !secret influxdb_password
max_retries: 9
default_measurement: state

ZHA Toolkit - Service for advanced Zigbee Usage

zha_toolkit:

zha:
zigpy_config:
ota:
ikea_provider: true
ikea_update_url: http://fw.test.ota.homesmart.ikea.net/feed/version_info.json

Example Bluetooth configuration.yaml entry

device_tracker:

  • platform: bluetooth_tracker

Try this:

  1. Comment out below part in your sensor.yaml:
platform: template
sensors:
sunrise:
friendly_name: “Sunrise”
unit_of_measurement: “”
value_template: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_rising”)) | timestamp_custom("%H:%M") }}’

sunset:
friendly_name: “Sunset”
unit_of_measurement: “”
value_template: ‘{{ as_timestamp(state_attr(“sun.sun”, “next_setting”)) | timestamp_custom("%H:%M") }}’
  1. In the configuration.yaml file in the “Links to external configuration files” add below:
template: !include template.yaml
  1. Create new file in the main homeassistant directory (same place where you have sensor.yaml, scripts.yaml, cameras.yaml etc) and name it “template.yaml”
  2. In the template.yaml file put below code:
- sensor:
  - name: "Sunrise"
    state: '{{ as_timestamp(state_attr("sun.sun", "next_rising")) | timestamp_custom("%H:%M") }}'

- sensor:
  - name: "Sunset"
    state: '{{ as_timestamp(state_attr("sun.sun", "next_setting")) | timestamp_custom("%H:%M") }}'
  1. Check the configuration and restart HA if everything is fine

PS.
Please use code formatter next time you post your code to make it easy to read.

I wish I could have

command_line: !include command_line_switches.yaml

AND

command_line: !include command_line_sensors.yaml

It’s more important to me to be able to think of it as a sensors instead of thinking of it as a command-line entity.

You can. Use the merge list include and point it to a folder containing those files

1 Like

I appreciate your answer as it exposed me to some organization techniques I hadn’t known before, but it doesn’t do what I’d like it to.

Ideally I’d like something like this:

/sensors/binary.yaml
/sensors/command_line.yaml
/sensors/main.yaml
/switches/command_line.yaml
...

This would require being able to load multiple separate files in to the command_line: key (it only takes a list).
I can’t use any of the include_dir* directives for this because it would require the structure to be:

/command_line/sensors.yaml
/command_line/switches.yaml

You have to put them both into the same folder containing no other integrations. Then use the merge dir list inclusion. You cannot put these files into separate folders

But that’s what I don’t want.

I know, I’m just explaining what’s possible.