Help with home assistant api call

I have no experience with programming or scripts, I would understand how to modify that to put my own variables in, but I don’t know what a curl command is, i assume curl is something i could write at the command prompt, anyway I’m quite clueless as how I can put a curl command into home assistant so i can fire of a curl command from automation.yaml

sorry I am very very very noob, I’m doing things outside of my experience level (which is basically installing home assistant a few weeks ago lol)

Ok. First things then.

What OS are you wanting to run this from? This is to cause a state change within Home Assistant, so I’m guessing you want to run this from a different system. Correct? So what OS does that system use?

I have hassio on a rasp pi 3b.

I have a open/close sensor and i want to change the state and attributes of an entity (climate.panasonic_aircon), when the sensor changes state. I am ok writing the automation.yaml for this I just get stuck on this part

action:
  # magic happens and the state / attributes of the entity changes

Ok. But I see you want to change the state of a device. To do that something has to trigger that state change. This is usually from some “external” source or from an automation or manual flip of a switch inside hassio.

So maybe I’m confused or lost. What are you actually trying to do?

Short answer

- alias: set climate state to off when aircon turns off
  trigger:
    - platform: state
      entity_id: binary_sensor.door_window_sensor_158d0001f38b1f
      from: 'on'
      to: 'off'
  action:
    # change the state of climate.panasonic_aircon to off

Long answer:

I have a dumb air conditioner.

I use it with the broadlink climate custom component:

If the air conditioner is turned on / off using the original IR remote then home assistant and the climate control doesn’t know that the aircon has be turned on.

I added a zigbee door / window sensor to the air conditioner to detect if it is turned on / off

I thought I might be able to use this to update home assistant to tell it what the air conditioner is doing.

edit: i wrote in my post that the state was reverting back, but it’s not the state is sticking. As I test i changed the climate.panasonic_aircon state to “tomatoes” and it is staying as tomatoes, so that is good.

tomatoes…I like that… ok I’m tired and I need some more nicotine. But here’s a shot.

Take a look at the climate component “Generic Thermostat” for some ideas and here’s a snip from my climate automations

action:
  - service: climate.set_temperature
    data:
      entity_id: climate_front_room_thermostat
      ac_mode: False
      temperature: 70

There’s a lot of options, but you would pass them to the entity_id through the data tag. Match the options with your climate component you are using. That’s not a exact example as I’m using the vera temperature component. But gives you an idea.

1 Like

Thanks. Unfortunately that’s not what I am after I already know how to call the climate service.

I want to change (overwrite) the state without calling the service. I can do it using the web interface, but I don’t know how to put that into a script.

The curl example I gave before should work with the “script component” just modify it to work. Does the same as the web interface.

However. With using hass.io it is limited to what is provided within hass.io. I don’t run hass.io anymore as it was too limiting as I have a bi-directional setup with a VeraPlus unit as my device controller. So I like having command line access and doing http calls between the two systems.

I fired up ssh into my hassio and i typed the curl command, it is available.

I still don’t know how to make a script with curl command as there is no documentation or examples.

like do i type that example into a text file and save it with the .py extension, where do i save it etc… i have done a lot of googling but I can’t find any tutorial or existing example that i can use to figure out how to fire off that curl command from inside an automation in hassio.

actually i think i found it?

actually when i check in HA i should be using the rest_command i think

I think it’s supposed to be this:

Configuration.yaml

rest_command:
  set_climate_state_idle:
    method: POST
    url: 'https://xxxxxx.duckdns.org:8123/api/states/climate.panasonic_aircon'
    password: 'xxxxxx'
    content_type: application/json
    payload: '{
    "state": "idle",
    "attributes": {
        "fan_mode": "auto",
        "operation_mode": "idle"
        }
    }'

Automation.yaml

- alias: set climate state to idle when aircon turns off
  trigger:
    - platform: state
      entity_id: binary_sensor.door_window_sensor_158d0001f38b1f
      from: 'on'
      to: 'off'
  condition:
    - condition: template
      value_template: "{{ not is_state('climate.panasonic_aircon', 'idle') }}"     
  action:
    - service: rest_command.set_climate_state_idle

but i get an error in configuration.yaml and I’m not sure what the issue is.

Try putting the payload all on one row

Im been strugeling for 15 hours straight now trying to accomplish the same thing as you.
Im using xeoma and has moved from Switchking to HA recently.

Erlier i sent http request like h_ttp://switchking_ip/devies/“device number”/turn_on when motion was detected.

As i understand you have made some binary sensor to listen to request from xeoma.

Trued to used command_line platform, restful-command and i have no clue what im doing wrong.
Even tried to send http request as h_ttp://ip-to my ha server/api/services/switch.turn_on/switch.my_entity
And also h_ttp://ip-to my ha server/api//switch.turn_on/switch.my_entity
But no luck.
when running h_ttp://ip-to my ha server/api/services/switch.turn_on/switch.my_entity i get 405 not allowed and h_ttp://ip-to my ha server/api//switch.turn_on/switch.my_entity (404 not found).

Can you please guide me in the right direction before i go nuts?

Best Regards
/Anders

Are you passing the x-auth in the header? It sounds like you have authentication enabled. In the API docs there’s an example of passing the auth credentials as well.

I tried with auth disable as well.

Tried to send it as a cURL script from my xeoma server instead and it works fine.

But dont understand how to send header with the http request from xeoma.

Still have configuration error if one line.

As mentioned on some forum i uset the start a program in xeoma insted. Start program cURL with the header parameters. Not as good att plain http request i xemoma but good enought.